CRYPTO_FUNDS_PENDING state, the OFI must initiate an
onchain transaction to fulfill the payment in USDC. CPN provides an API to help
prepare and validate the onchain transaction call data, and to broadcast the
transaction and monitor its state.
There are two versions of the Transactions API: V1 and V2. This guide provides
information on both versions. Note that your quote must match the version of the
API that you are using.
Prerequisites
Before you begin, ensure that you have:- Created a quote through the CPN API. If you are following the Transactions V2
example, your quote should be created with the
transactionVersionparameter set toVERSION_2. - USDC in your sender wallet
- (Transactions V1 only) Native tokens in your sender wallet
- (Transactions V2 on EVM chains only) Granted a USDC allowance to the
Permit2contract. See How-to: Grant USDC Allowance to Permit2 for more information. - (Solana only) Ensure your Solana account has been initialized and funded.
Note: For Transactions V2, gas fees are not charged in native tokens, but in
USDC. They are determined at quote creation instead of transaction creation in
the quote
fees field. The gas fee is collected by Circle’s payment settlement
smart contract during onchain transaction processing.Steps
Use the following steps to create and broadcast a USDC transfer to the blockchain:Step 1: Prepare the call data
Call the create transaction endpoint to get an unsigned message object. Note that transaction objects differ between EVM blockchains and Solana. For Transactions V2, call the create transaction V2 endpoint to get an unsigned message object. Transactions V2 supports EVM chains only. The API call must include the sender wallet information (which must be an EOA wallet). The rest of the transaction data such as amount, chain, destination address, and other information is populated automatically by CPN using the payment record.Step 2: Create and sign the transaction
Review the unsigned message object and ensure that it matches your expectations for the crypto transaction. Depending on the blockchain, the signing process varies.EVM
- Transactions V1
- Transactions V2
When the unsigned data has been confirmed, you must sign it in accordance with
EIP-712. Next, you construct an
EIP-3009 transaction from the signed
data:Sign this transaction data and move on to the next step.
- Extract the signature. Extract the signature components (
v,r,s) from the signed typed data. - Encode the function call. Using the ERC-20 smart contract’s ABI for the
TransferWithAuthorizationfunction, encode the function call with the required parameters: sender address (from), recipient address (to),validAfter,validBefore,nonce, and the signature components,v,r,s. This encoding creates the data field for the raw transaction. - Construct the transaction object. Build a raw transaction object that includes the target contract address (USDC), the encoded function call data, and other necessary parameters such as nonce, gas limit, max fee per gas, max priority fee per gas, and chain ID.
- Serialize the transaction. Serialize the transaction object into the proper RLP-encoded format so that it can be signed.
TransferWithAuthorization contract execution.JSON
Solana
- Transactions V1
- Transactions V2
For V1, the transfer data for Solana follows Solana’s If you are using the Circle Wallets, you can use the
sign transaction
endpoint to sign the transaction object.
Ed2559 transaction
format. After confirming the unsigned data, a transaction object is constructed
with the transfer data. You sign the transaction object and submit it to the
API.To sign the transaction object, you can deserialize the messageToBeSigned
field from the
POST /v1/cpn/payments/:paymentId/transactions
endpoint, and sign it using a Solana library with your wallet key pair.Note: Once signed, Solana transaction objects expire after one minute, so
you should submit it immediately.