Claim on Any Chain in Any Token
Cross-Chain claiming (also called "X-Chain" for short) provides a seamless and flexible way to claim tokens across different blockchain networks. There are 2 primary approaches to claim links cross-chain:
- Gasless claim through our API/relayer. We will execute the transaction and pay all the transaction + bridging fees, but we will take a small portion of the Link's amount as a compensation. Currently we take 2%.
- Claim by signing the transaction yourself. This way you will have to execute the transaction on the source chain and pay the bridging fee, but there will be no Peanut-specific fee involved.
Gasless Claiming
To claim a Link gaslessly through our API, use the
claimLinkXChainGasless
function:plain textconst result = await peanut.claimLinkXChainGasless({ link, // the entire link as string. recipientAddress, // receipient address on the destination chain. destinationChainId, // id of a supported destination chain. destinationToken, // optional. address of the token on the destination chain, 0x00..00 for native token. If not specified, the address of the token on the source chain is used. APIKey, // api key for the relaying API. baseUrl, // optional. Use if you have a custom realying api that the link should be claimed through. squidRouterUrl, // optional. Use if you want to get squid data from a custom endpoint. isMainnet, // optional. Use when experimenting on testnets. Default: true. slippage, // optional. Max slippage when swapping between source and destination tokens. })
Claiming Yourself
To claim a Link by signing the transaction yourself, follow these three steps:
- Create a cross-chain claiming payload via
createClaimXChainPayload
function.
- Create an Ethersv5 transaction request out of this payload by using
populateXChainClaimTx
function.
- Sign the transaction request with your own wallet & submit it to the blockchain. There is a helpful
signAndSubmitTx
function.
The following are helpful cross-chains functions.
createClaimXChainPayload
To use the
createClaimXChainPayload
function, follow the code snippet below:plain textconst xchainClaimPayload = await peanut.createClaimXChainPayload({ destinationChainId, destinationToken, // optional. address of the token on the destination chain, 0x00..00 for native token. If not specified, the address of the token on the source chain is used. link, // the entire link as string. recipient, // receipient address on the destination chain. squidRouterUrl, // optional. Use if you want to get squid data from a custom endpoint. isMainnet, // optional. Use when experimenting on testnets. Default: true. slippage, // optional. Max slippage when swapping between source and destination tokens. })
populateXChainClaimTx
To use the
populateXChainClaimTx
function, follow the code snippet below:plain textconst xchainUnsignedTx = await peanut.populateXChainClaimTx({ payload, // payload generated in createClaimXChainPayload. provider, // optional. Ethers provider connect to a node. })
Notes
- Ensure you have the necessary environment variables set, particularly
PEANUT_API_KEY
if you are claiming though our API. Fill out this form to get your very own peanut-api-key!
- Be aware of the network fees and slippage settings if you pay the x-chain gas. Cross-chain claiming gas fees can be high depending on the source and destination chain.
- The
claimLinkXChainGasless
function is convenient but remember that in the future it will have a 2% fee.
- Always test your implementation in a testnet environment before deploying to production.