2

I want to get the approve signature for the user's erc20 token. But I will not send this signature directly to the network. I'll send it whenever needed. How can I do that?

1 Answer 1

1

You can use populateTransaction bucket in ethers.Contract, and then sign it.

const contract = new ethers.Contract(address, abi, provider);
const unsignedTx = await contract.populateTransaction.approve(spender, amount);

const wallet = new ethers.Wallet('0xprivatekey');
const signedTx = await wallet.signTransaction(unsignedTx);

// at a later point in Time
await provider.submitTransaction(signedTx);

The signing step depends on the signer you're using. Some signers like Metamask that also act as a provider may not allow you to do that, while signers like Wallet, Ledger will give you the signed transaction without submitting to the network.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.