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?
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.