I am using truffle console to deploy contracts and using Nodejs/web3js to interract with it. I wanted to use ethereumjs-tx for signing transaction, here is the reference link. I am not sure ,how can i find chain id and network id of local blockchain which i need to create rawtransaction. i.e

const customCommon = Common.forCustomChain(
    name: 'my-network',
    networkId: ???,
    chainId: ???,
  • networkId and chainId 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). – goodvibration Oct 10 '19 at 8:14
  • 1
    You can probably also obtain it programmatically from the web3 instance which you're initializing in your script. – goodvibration Oct 10 '19 at 8:15
  • 1
    With web3 v1.0 the following works web3.eth.net.getId(). – Ismael Oct 10 '19 at 16:28
  • 1
    no, networkId and chainId are NOT the same, and the purpose of chainId is to resist transaction replay attacks. So this distinction is actually super-important but little-understood. e.g. see medium.com/@pedrouid/… – Chan-Ho Suh Dec 18 '19 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.