Talha Malik
Talha Malik

Reputation: 41

Signed Transaction Once Broadcast on any Evm comptable blockchain

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

Upvotes: 0

Views: 275

Answers (1)

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83706

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

Upvotes: 0

Related Questions