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.
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. 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
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:- 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
On Solana, the transfer data follows Solana’sEd2559 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.
Note: Once signed, Solana transaction objects expire after one minute, so
you should submit it immediately.