Gasless depositing works via EIP-3009. USDC supports EIP-3009.
Create a payload to submit to the Peanut Smart Contract. This involves an EIP-712 message to be signed in the user's wallet (this is not a transaction, just a signature).
The EIP-712 message will approve the token via EIP-3009 to be pulled from the user by Peanut Protocol
const { payload, message } = await peanut.makeGaslessDepositPayload({
address, // address of the user's wallet
contractVersion, // peanut version. At least 'v4.2'.
password, // unique password for the link, can be generated via 'getRandomString' function
linkDetails: {
chainId,
tokenAmount,
tokenType, // must be 1 for ERC-20
tokenAddress,
tokenDecimals,
},
})
There should be a method in your wallet API called signTypedData
. Use it to sign the message
obtained in the previous step.
Execute the gasless deposit via Peanut's API
const { txHash } = await peanut.makeDepositGasless({
APIKey, // peanut api key
payload, // payload obtained in step 1
signature, // signature obtained in step 2
})
And that's it! Congrats! Your user just sent some tokens without paying for gas!
If you want to execute the gasless deposit via your own relayer instead of using Peanut's. There is a helpful function for you! It computes the to
address and calldata (called data
).
Simply sign it with your relaying wallet and execute!
const { to, data } = await peanut.prepareGaslessDepositTx({
payload, // paylaod obtained in step 1
signature, // signature obtained in step 2
})