Search code examples
javascriptethereumweb3jsmetamaskethers.js

Sign transaction without broadcasting it with metamask (not using private key)


I'm trying to sign a transaction without broadcast using metamask. I have tried web3js and etherjs (eth_signTransaction) but neither worked. How to do this?

I think opensea is signing message and then using it for transaction. How did they do this?

  1. using web3js. I have tried this. But I get

MetaMask - RPC Error: Method not supported

const signedTx = await web3.eth.signTransaction(tx, accounts[0])
  1. using etherjs. I have tried this. But I get

Error: signing transactions is unsupported (operation="signTransaction", code=UNSUPPORTED_OPERATION

const signedTx = await signer.signTransaction(tx)

Solution

  • Metamask currently does not support the RPC method that is used to sign transactions. See the GitHub issue discussing why they chose not to implement it: https://github.com/MetaMask/metamask-extension/issues/3475

    EDIT:

    I think opensea is signing message and then using it for transaction. How did they do this?

    The way that OpenSea allows minting in a gasless manner is actually quite simple: they don't mint the NFT until it is purchased by somebody. OpenSea then mints the NFT themselves, using an owner 'bypass' present in the contract it deploys.