I have a public / private keys. I release a contract with these keys. I want some user to withdraw a token / ether, so I sign some message like {withdraw: 10, nonce:1} offchain. User uses this signed message to call some withdraw method. How can I confirm in that withdraw method that I signed that message? Either Python or PHP for signing the message will do.

1 Answer 1


You're looking for the "meta transactions" concept.

The general idea and usual approach is:

  1. Organize the transaction parameters off-chain and hash the values.
  2. Sign the hash off-chain, e.g. MetaMask.
  3. Now assemble the parameters and the signature into a message and send it to a relayer.

Someone has to send it to the blockchain and the contract has to dig for the signer. The relayer is usually thought of as agnostic, but they pay for gas and send the transaction to its destination contract.

The receiving contract has to be aware of meta transactions so it can interpret this package and respond properly. It will usually:

  1. Unpack the parameters and work out, for itself, what the message hash must be.
  2. Use the signature parameter given and the computed hash to determine the signer address with ecrecover.
  3. Use the derived address in place of msg.sender and carry on.
  4. Such a contract may tip the relayer (msg.sender) to create a business model that compensates for gas invested.

There's an example over here that highlights a tricky implementation detail. The example uses the OpenZeppelin ECDCA library - a good place to start. Sign message with web3 and verify with openzeppelin-solidity ECDSA.sol

Hope it helps.

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.