0

I am trying to make a signed transaction that can be broadcasted on any evm compatible blockchain. How i am doing it

try{
  const contractInstance = new web3.eth.Contract(contractAbi);
  const contractTrx = contractInstance.deploy({
    data: 'byteCode'
  })
  const createTransaction = await web3.eth.accounts.signTransaction({
    from: '0x.....',
    data: contractTrx.encodeABI(),
    gas: 3000000
},
'privateKey'
)
console.log('createTransaction ', createTransaction.rawTransaction);
} catch (e) {
  console.log(e.message);
  throw e;
}

This code gives signed transaction and it can be broadcasted and works but it depends on which provider i am using. let say i use polygon provider and sign this transaction but broadcast it on ethereum network then it gives error as invalid sender. i wanted to create some script that can generate generic signed transactions that can be broadcasted on any evm

saastn
  • 5,717
  • 8
  • 47
  • 78

1 Answers1

0

Transactions include nowadays chain_id parameter that prevents broadcasting the a transaction on a wrong network.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • but i wanted to create a generic transaction that can be broadcasted on any evm chain. it just has to be signed – Talha Malik Feb 09 '23 at 13:24
  • if i dont specify chainId and broadcast it on the same chain whom provider is used then it works fine – Talha Malik Feb 09 '23 at 13:25
  • What you want and what is practical are two different matters. Unfortunately, what you are asking is not practically possible. – Mikko Ohtamaa Feb 09 '23 at 13:26
  • take a look at following link https://github.com/eth-infinitism/account-abstraction/blob/develop/src/Create2Factory.ts there is a variable named as factoryTx it holds signedTransaction data. if you see deployFactory() function it is actually deploying a contract whose transaction is signed. – Talha Malik Feb 09 '23 at 13:31
  • it works on any chain you wants – Talha Malik Feb 09 '23 at 13:31
  • Thank you. I was not aware of this, I will take a look. – Mikko Ohtamaa Feb 09 '23 at 13:50
  • Note that the example you linked is for deterministic addresses for contract deployments. It is a bit different problem from generic transaction broadcasting. – Mikko Ohtamaa Feb 09 '23 at 13:59