◎Solana Purchase Transactions

How to create a transaction for Solana so users can purchase your goods and services with Coinflow's platform

On the Solana blockchain all transactions are a series of atomic instructions executed in order. Coinflow works by wrapping your transaction's instructions with two Coinflow program instructions. This way we can modify the user's CFLOW balance, send them USDC or other tokens necessary to complete the purchase, and then clean up after the fact so the user does not have more of those tokens than when they started.

The Coinflow program will verify that all of the instructions in the program meet the following conditions:

  1. Belong to a whitelisted program
  2. Are one of the following programs:
    1. System Program - [11111111111111111111111111111111](https://explorer.solana.com/address/11111111111111111111111111111111)
    2. Associated Token Program - [ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL](ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL)
    3. Memo Program - [Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo](https://explorer.solana.com/address/Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo)
  3. Token Program instructions that are not Transfer or TransferChecked are allowed without any restrictions

USDC Purchases

If your contract accepts USDC as payment for goods or services, this is the section for you. The transaction that is constructed and passed into the CoinflowPurchase component or the Redeem API, will be exactly the same as a user who is bringing their own USDC. Coinflow's systems will automatically modify your transaction to wrap it in the Coinflow program instructions.

Purchases in Other Tokens

Contracts which accept all other tokens, including SOL, will operate much in the same way as a regular USDC purchase. However, an added step is that the Coinflow Setup Transaction will automatically swap the user's USDC to the token which your smart contract accepts. This means that the token must have a TOKEN/USDC pool with ample liquidity on the Orca decentralized exchange.

Another fun quirk of this is that because Solana transactions are limited to 1232 bytes with each public key taking 32 bytes, for the vast majority of cases this swap will exceed the transaction size set by Coinflow. Therefore, when specifying a transaction which makes a purchase to the token the Coinflow Redeem API will always return a Versioned Transaction. That means that all wallets that your website/application can connect with should be compatible with V0 Transactions.

Token Transfers

If your transaction is simply transferring tokens from the user's wallet to a wallet owned directly by your company, Coinflow supports Transfer and TransferChecked instructions with the caveat that the associated token address of the token owned by your wallet is allow-listed with the coinflow program.

Gas Fee Paying

The Coinflow APIs will automatically add a fee payer for your transactions which prevents the user's wallet from needing to have SOL. You can also specify your merchant's Coinflow fee payer wallet, which is on the homepage of the admin dashboard. It displays as a signer key in the transaction, which will be able to pay any rent on behalf of the users. If you specify your merchant fee payer wallet in the transaction it will also become the transaction's feePayer.

Rent Paying

Many use cases in Solana require the user to also pay SOL as rent. This poses an issue with traditional onramps where the user must both purchase USDC AND SOL to complete the purchase of a good/service on chain. Coinflow simplifies this process by allowing merchants to specify the number of lamports needed to pay for the rent of a particular transaction. When the user is checking out the price of the SOL for that rent will automatically be added to the user's total purchase price, and on chain credits will be sent to the user for that amount. The Coinflow program will then exchange the users credits for the number of lamports passed in, and the merchants program can use those to pay for rent. Just like Coinflow Credits any residual lamports will be reconverted to Coinflow Credits automatically, meaning the user will never have access to any liquid crypto.

In order to use Coinflow Rent Payments in the SDK simply pass the rent prop like so to CoinflowPurchase

  rent={{lamports: 1000000}} //0.001 SOL

In order to use Coinflow Rent Payments with the APIs simply pass the {lamports: 1000000} object into the Checkout and Redeem API's.