I started my private network with id = 15452:

geth --networkid 15452

Is it possible to get the number inside solidity smart contract?


I don't think that's possible because by design there is clear separation between the EVM (turing machine) and the Ethereum network.

In the same manner as a virtual machine on your PC, it is sandboxed and isolated from the network, whilst still being a part of it. This isolation is what makes it impervious to hack attacks and corruption, essentially fortifying it.

However, you could simply do this in the contrat

pragma solidity ^0.5.2;

contract MyContract {
    uint networkid;

    constructor(uint _networkid) public {
        networkid = _networkid;

Chainlink is doing something clever. They deployed a contract on each network with the same account and nonce. This means the contract will have the same address in each network.

address constant private LINK_TOKEN_POINTER = 0xC89bD4E1632D3A43CB03AAAd5262cbe4038Bc571;

Then they use this address to receive the proper address for the LINK token. You could basically do the same and add functions to the LINK_TOKEN_POINTER contract as you need them.

Full contract at https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/ChainlinkClient.sol

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.