Skip to main content
This guide walks you through the steps to request, lock, and fulfill your first quote using CPN.

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.
Before you begin this quickstart, ensure you have: This quickstart provides API requests in cURL format, along with example responses.
Note: The base URL for all API endpoints is https://api-staging.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 /quotes endpoint, providing the source currency and destination amount. The endpoint returns a list of quotes from various BFIs with the rate, expiration time, USDC settlement window, and unique ID.
Shell
Response
JSON

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.
Shell
Response
JSON

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 the optional 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
Response
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. The endpoint returns an unsigned onchain transaction object and a transaction ID.
Shell
Response
JSON

3.2. Sign the call data

Using the /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
Response
JSON
Create a file called cpn_signature.py and add the following code to it, replacing circle_signature with the signature returned from the endpoint, and replacing the message object values with the corresponding values from the response in step 3.1.
Python
When run, the script outputs the final call data.

3.3. Sign the transaction

In the previous step, you signed the call data to authorize the transaction. Next, you must create and sign the raw transaction using the /sign-transaction endpoint. Include the call data from the script as the data field and the wallet ID from your Circle Wallet. The raw transaction to be signed can be composed like the following example:
JSON
Use the following endpoint to sign the transaction:
Shell
Response
JSON

3.4. Submit the signed transaction

Use the /payments/{paymentId}/transactions/{transactionId}/submit endpoint to submit the transaction to be broadcast to the appropriate blockchain. You should use the signed transaction and transactionId from the previous steps to populate the endpoint call.
Shell
Response
JSON
Once the onchain transaction is confirmed by the BFI, the BFI initiates a fiat payout to the recipient. As the fiat payout progresses, the OFI is notified by webhook notifications.