I am using truffle console to deploy contracts and using Nodejs/web3js to interact with it. I wanted to use ethereumjs-tx
for signing transactions, here is the reference link. I am not sure how can I find the chain id and network id of the local blockchain for which I need to create rawtransaction. i.e
const customCommon = Common.forCustomChain(
'randomchainNmae',
{
name: 'my-network',
networkId: ???,
chainId: ???,
},
'petersburg',
)
networkId
andchainId
are the same thing AFAIK. And it's not on Truffle side, but on Ganache side (or whatever you're using as a blockchain provider). On Truffle side you can filter specific network IDs via the Truffle configuration file (truffle.js or truffle-config.js). But the configuration of the actual ID is on the provider side. For example, if you ARE using Ganache, then you can use-i
or--networkId
in order to specify the network id that ganache-cli will use to identify itself (see here).web3
instance which you're initializing in your script.web3.eth.net.getId()
.networkId
andchainId
are NOT the same, and the purpose ofchainId
is to resist transaction replay attacks. So this distinction is actually super-important but little-understood. e.g. see medium.com/@pedrouid/…