Don’t have an API key? Get started here.

The Peaze API allows you to easily relay transactions to the Peaze Protocol and utilize automated swapping, bridging, and gas abstraction.

The API has four core endpoints:

  1. Estimate Single-chain Transaction
  2. Estimate Cross-chain Transaction
  3. Execute Single-chain Transaction
  4. Execute Cross-chain Transaction

In the following walkthrough, we’ll go through the steps to execute a cross-chain transaction. The steps for a single-chain transaction are essentially identical.

Step 1: Estimate transaction

First, you’ll want to gather details about the transaction along with data to sign:

curl --location 'https://api.peaze.com/api/v1/cross-chain/estimate' \
--header 'X-Api-Key: <YOUR-PEAZE-API-KEY>' \
--header 'Content-Type: application/json' \
--data '{
    "transactions": [{
        "to": "0x...",
        "data": "0x..."
    },
    {
        "to": "0x...",
        "data": "0x..."
    },
    ...],
    "tokenAmount": 100000000,
    "userAddress": "0xAAA...",
    "sourceChain": "137",
    "destinationChain": "10"
}'

Here, the transactions field is an array of transactions that you want to execute on the destination chain.

For each transaction, the to field is the address of the contract you want to interact with, and the data field is the encoded data for the transaction.

The tokenAmount field is the amount of USDC needed for requested transactions (100 USDC in our example).

For more details, please check out the reference here.

You will receive a response that looks like this:

{
    "costSummary": {
        "tokenAddress": "0x...",
        "tokenSymbol": "USDC",
        "totalAmount": 102.51,
        "baseAmount": 100.00,
        "gasCost": 2.00,
        "peazeFee": 0.51,
        "gasCostInWei": "...",
        "gasUsedOnDst": "658209"
    },
    "typedData": {
        "td712": {...},
        "td2612": {...}
    }
}

costSummary gives an overview of how much this transaction will cost.

typedData are unsigned data objects that you will use to generate signatures and submit for execution in the final step.

For more details, please check out the references for single-chain and cross-chain transactions.

Step 2: Sign typed data

Sign the typed data objects in the response from step 1 to generate the necessary signatures.

The way in which you generate these signatures is highly specific to your implementation, but some examples are ethers’ signTypedData and viem’s signTypedData.

For a concrete example using ethers.js, please refer to our quickstart.

Step 3: Execute transaction

Finally, execute the transaction by passing in the necessary parameters and signatures:

curl --location 'https://api.peaze.com/api/v1/cross-chain/execute' \
--header 'X-Api-Key: <YOUR-PEAZE-API-KEY>' \
--header 'Content-Type: application/json' \
--data '{
    "sourceChain": "137",
    "destinationChain": "10",
    "signatures": {
        "sig721": "0x...",
        "sig2612": "0x..."
    },
    "txValue": "<VALUE OF gasCostInWei>",
    "gasUsedOnDst": "<VALUE OF gasUsedOnDst>",
    "message": {<JSON CONTENT OF td712.message>},
    "domain": {<JSON CONTENT OF td712.domain>},
}'

As a bit of clarification:

  • txValue is the value that our relayer with send along with the transaction, which will be used for the bridge fee
  • gasUsedOnDst is the amount of gas used on the destination chain

We will simplify these parameters in the future to minimize the amount of data you need to pass in.

You will receive a response that looks like this:

{
  "transactionId": "<transactionId>",
  "transactionHash": "0x...",
  "blockExplorerUrl": "https://..."
}

That’s it! The transaction is being executed on-chain. You can check its cross-chain status using the Layer 0 Explorer, where you simply need to paste in the returned transaction hash.

For more details, please check out the references for single-chain and cross-chain transactions.

We also highly recommend to check out our quickstart guide for a complete example using ethers.js.