Search code examples
blockchainethereumsoliditysmartcontractsgo-ethereum

Is it possible to predefine smart contracts in genesis.json?


I encountered exactly the same issue as this https://ethereum.stackexchange.com/questions/7707/is-it-possible-to-preload-contracts-in-the-genesis-block?rq=1

Agian, is it possible to predefine a contract by assigning alloc -> code field like this,

enter image description here

However, it seems like no matter which method in the contract I call, it always returns the Bytecode of the contract itself regardless of the logic and content of this method.

enter image description here

And this might be the reason when I deploy a contract:

enter image description here

When I call test(), obtaining:

enter image description here which is not a string.

When I call test2(), obtaining:

enter image description here which is a very big number.

When I call test3(1), obtaining a false, which is not 1 == 1.

I have taken a look through the related threads, found this, https://ethereum.stackexchange.com/questions/30366/how-does-the-genesis-json-file-define-the-initial-state-of-the-blockchain

It looks like the storage setting is necessary but I have totally no idea what key/value I should write.

How could I deal with this case then?


Solution

  • However, it seems like no matter which method in the contract I call, it always returns the Bytecode of the contract itself regardless of the logic and content of this method.

    This sounds to me like you included --bin instead of --bin-runtime from solc

    How did you generate the code to be included?

    The --bin code is the code that is run on the contract creation transaction, which returns the actual code to be included in the contract (which is --bin-runtime).