Note: This quickstart uses EVM blockchains to demonstrate how to create
and execute a payment on CPN. For Solana, you would follow a similar process
with some differences in the signing process.
Prerequisites
Note: This quickstart uses Circle Wallets to demonstrate how to create and
execute a payment on CPN. To create and manage a Circle Wallet, you also need a
Circle Developer account. You don’t need to use Circle Wallets (or a Circle
Developer account) in your production implementation, however. You can bring
your own wallet provider as long as it meets the
requirements for CPN.
- Obtained an API key for CPN from Circle
-
Created a Circle Developer Account
- Registered your entity secret
- Created a new wallet set using the API
- Created at least one EOA wallet in the wallet set (see the link in the
previous bullet)
- If you are using Transactions V1, the wallet should be on
EVM-TESTNET - If you are using Transactions V2, the wallet should be on
ETH-SEPOLIA
- If you are using Transactions V1, the wallet should be on
- Have access to the wallet ID for the EOA wallet
- Funded the wallet with testnet USDC and testnet ETH.
-
Python installed on your development machine
- The latest
jwcrypto,web3,eth_utils,hexbytes, andeth_abilibraries are installed with thepippackage manager
- The latest
- cURL installed on your development machine
-
(If using Transactions V2) Granted a USDC allowance to the
Permit2contract. See How-to: Grant USDC Allowance to Permit2 for more information. - (Optional) a configured webhook notification endpoint
Note: The base URL for all API endpoints is
https://api.circle.com/v1/cpn
for both sandbox and production environments. The API determines if a request is
for testnet or mainnet based on the key used to authenticate the request.Part 1: Request a quote
Request quotes for a USDC to MX payment with the SPEI payment method. Request quotes with the create a quote endpoint, providing the source currency and destination amount. For Transactions V2, you must specifytransactionVersion as VERSION_2. The endpoint returns a
list of quotes from various BFIs with the rate, expiration time, USDC settlement
window, and unique ID.
- Transactions V2
- Transactions V1
Part 2: Create a payment
Use the API to get the requirements for a payment, accept the quote, and create a payment.2.1. Get payment requirements
Call the/payments/requirements
endpoint with the quote ID to get the requirements for a payment. The endpoint
returns an object describing the required fields for the compliance check. The
optional field for each parameter defines if the parameter must be included in
the response constructed in the next step.
2.2. Encrypt the required fields
Construct a JSON object with the information requested in the previous step. For each schema, the properties that you must include are outlined by theoptional
field. Encrypt the object with the jwk certificate provided in the quote
response.
The correct format for travel rule data and beneficiary account data is a JSON
array of objects where each object contains two properties: name and value.
You can review an example of each field in the
encryption how-to.
Create a file called cpn_encryption.py and put the following code in it,
replacing the requirements_response_json parameter with the contents of the
response from the previous step, and the certificate_json parameter with the
jwk from the quote response. When you run the script, it outputs the encrypted
beneficiary and travel rule data to the console.
Python
2.3. Create a payment
After the quote is accepted, create a payment by calling the/payments endpoint. You need
to provide the quote ID and encrypted sender and receiver information. The
endpoint returns a unique payment ID and the initial status of the payment.
Note: You must create the payment before the quote expires, otherwise you’ll
need to request a new quote.
Shell
JSON
Part 3: Create a transaction
Use the API to create a blockchain transaction to transfer USDC. Sign the transaction locally, and use the API to broadcast it to the blockchain.Note: This quickstart uses Circle Wallets to act as the originator wallet
for the onchain payment. This section uses the wallet ID from the EOA wallet
mentioned in the prerequisites section.
3.1. Initiate the onchain transaction
Initiate the onchain funds transfer by calling the/payments/{paymentId}/transactions
endpoint with the payment ID from the previous step, and other
transaction-related parameters. Note that if you are using Transactions V2, you
should use the
create transaction V2
endpoint. The endpoint returns an unsigned onchain transaction object and a
transaction ID.
- Transactions V2
- Transactions V1
3.2 Sign the onchain transaction
Note: The following steps are for EVM blockchains. For Solana, you would
follow a similar process with some differences in the signing. Please refer to
How-to: Create an Onchain Transaction for
more information.
- Transactions V2
- Transactions V1
Using the
Response
/sign/typedData
endpoint, input the messageToBeSigned object from the previous step along with
your entity secret and wallet ID. The transaction parameter should be
stringified from the
messageToBeSigned field from the transaction response.Shell
JSON
3.3. Submit the signed transaction
- Transactions V2
- Transactions V1
Use the
Response
/v2/cpn/payments/{paymentId}/transactions/{transactionId}/submit
endpoint to submit the transaction to be broadcast to the blockchain.
You should submit the EIP-712 typed data signature you obtained from the /sign/typedData endpoint in
step 3.2. as signedTransaction.Shell
JSON
Note:
transactionHash will be provided after transaction is in COMPLETED
status. You can monitor for the transactions webhook events to get the
transactionHash.