是否可以在 genesis.json 中预定义智能合约?

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

我遇到了和这个完全一样的问题https://ethereum.stackexchange.com/questions/7707/is-it-possible-to-preload-contracts-in-the-genesis-block?rq=1

Agian,是否可以像这样通过分配 alloc -> code 字段来预定义合约,

但是,似乎无论我调用合约中的哪个方法,它总是returns合约本身的字节码,无论该方法的逻辑和内容如何。

这可能是我部署合约的原因:

当我调用test()时,得到:

这不是字符串。

当我调用test2()时,得到:

这是一个很大的数字。

当我调用 test3(1) 时,得到一个 false, 这不是 1 == 1.

我浏览了相关主题,找到了这个,https://ethereum.stackexchange.com/questions/30366/how-does-the-genesis-json-file-define-the-initial-state-of-the-blockchain

看起来存储设置是必要的,但我完全不知道我应该写什么key/value。

那我该如何处理呢?

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.

这对我来说听起来像是您从 solc

中包含了 --bin 而不是 --bin-runtime

您是如何生成要包含的 code 的?

--bin代码是运行合约创建交易中的代码,returns是要包含的实际代码在合同中(即--bin-runtime)。