Solidity编译器的可能输出包括创建字节码和部署(运行时)字节码。但是,这个已编译的已部署字节码可能与实际部署在块链上的字节码不一样。如果契约需要构造函数参数来初始化不可变变量,则可能是这种情况。因此,如何使用上述构件(创建字节码、部署字节码、构造函数参数)并生成实际部署的字节码,而不实际部署它。一种可能的选择是部署到(本地) testnet,然后查看已部署的字节码,但这似乎是过头了。
好的,为了使事情更清楚,这是术语(我没有编出来:字节码、init代码、由bytedcode部署的字节码、创建字节码和运行时字节码之间有什么区别?):
deployed bytecode = runtime bytecode
actual deployed bytecode = actual runtime bytecode
这一问题涉及的事实是,有时:
deployed bytecode (as predicted by compilation) =/= actual deployed bytecode (after deployment)
事实上,当契约使用不可变变量时,最后一个公式通常适用。
发布于 2021-03-09 11:16:37
这个GitHub问题帮我找到了答案。基本上,我所需要的可以通过ethereumjs-vm模块来实现:
const VM = require("ethereumjs-vm").default;
const BN = require("bn.js");
const vm = new VM();
vm.runCode({
code: Buffer.from(creationBytecode + abiEncodedConstructorArguments, "hex"),
gasLimit: new BN(...),
}).then(results => {
const actualDeployedBytecode = results.returnValue.toString("hex");
console.log(actualDeployedBytecode);
});https://ethereum.stackexchange.com/questions/94396
复制相似问题