0

I want the user to sign a transaction for Eth transfer but execute it at a later point in a smart contract.

Example:

  1. I want the user to sign a transfer to Address B of 1 ETH
  2. The signed transaction is later relayed to a smart contract, where it may choose to execute that signed message and do the transfer.
  3. The smart contract may return some of the ETH to the user's address later.

I know how it can be done for an ERC20 token but mostly looking to do for ETH.

1 Answer 1

0

You can construct an unsigned transaction and use signTransaction method.

const unsignedTx = {
  to: '0x123...',
  value: ethers.utils.parseEther('1.234') // ether amount
}

const signedTx = await wallet.signTransaction(unsignedTx); // hex string

// at later point in time
await provider.submitTransaction(signedTx)

Also note that the signTransaction is only available if the signer supports it. E.g. Metamask does not support it, but you can do that with those that support it, like hardware wallets and ethers.Wallet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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