具体来说,在使用Mist的时候,我通过Mist GUI创建合约后,我希望能够在Etherscan上验证源代码。 但是,Etherscan要求人们提供编译器版本以及是否启用了优化(optimizations)。

  • 对于我使用的Mist版本,我如何才能找到该编译器版本呢?
  • 优化(optimizations)是始终启用还是始终禁用呢?
  • 测试网络与主网有什么区别?

注意:我正在寻找如何确定编译器版本的答案,而不是当前的Mist编译器版本(这将瞬间改变答案)。

原文地址

2 人回答 0

2 个回答
投票数
最旧发布
最近发布

回答发布于 2018-09-10 16:31:26

Mist/Ethereum Wallet现在有一个内置的编译器——除了教程中的为了教学创建、编译和部署合约的屏幕截图之外,它并不是很好的文档。但是,Mist编译器的版本以及它是否经过优化是很难搞清楚的。

但是,这并不一定能解决你在EtherScan上得到验证的问题。无论我尝试过什么(或尝试了多少次),我都无法获得匹配的代币代码。如果你想和我一起潜水,请参阅此评论的最后。


如果在EtherScan上获得验证对你来说很重要,那么请在此处编写你的Solidity代码,然后使用浏览器Solidity编译它:http//chriseth.github.io/browser-solidity/

然后使用该字节码进行部署。我没有对它进行测试,但它为示例代币合约生成的代码与EtherScan生成的代码相匹配。我猜想EtherScan是使用了相同的基于浏览器的编译器来检查和验证合约。


如果你使用的是Mix IDE/Solidity,则可以通过到(在Mix IDE中)File/Mix/Help->About中来查看Solidity版本。


如果你使用solc/Solidity(命令行界面),你可以使用命令web3.eth.compile,然后生成类似于下面的东西:

contract = eth.compile.solidity(source).test
{
  code: '605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056',
  info: {
    language: 'Solidity',
    languageVersion: '0',
    compilerVersion: '0.9.13',
    abiDefinition: [{
      constant: false,
      inputs: [{
        name: 'a',
        type: 'uint256'
      } ],
      name: 'multiply',
      outputs: [{
        name: 'd',
        type: 'uint256'
      } ],
      type: 'function'
    } ],
    userDoc: {
      methods: {
      }
    },
    developerDoc: {
      methods: {
      }
    },
    source: 'contract test { function multiply(uint a) returns(uint d) { return a * 7; } }'
  }
}

这将编译你的代码并为你提供编译器版本等信息。

更多信息


Optimization-优化是你自己做出的选择。 通过solc,你可以使用--optimize标志。 你可以从此处阅读到有关此神奇Optimization属性的更多信息:Solidity优化程序是如何运行的?( How does the solidity optimizer work?) 我认为Mist正在根据以下事实进行优化:当我在EtherScan上选择“未优化”时,我的相似度为73%,当我选择优化时,我的相似度为93%。


合约测试:

我已经使用Mist v 0.5.2创建了合约https://www.ethereum.org/token#the-code,但没有对代码进行任何更改。

Etherscan.io收到/Mist发送的合约代码如下:

0x6060604052361561008d5760e060020a600035046306fdde03811461009557806318160ddd146100f257806323b872dd146100fb578063313ce5671461012d57806354fd4d501461013957806370a082311461019357806395d89b41146101ab578063a9059cbb14610207578063cae9ca5114610236578063dc3080f214610398578063dd62ed3e146103bd575b6103e2610002565b6103e460008054602060026001831615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260045481565b610452600435602435604435600160a060020a0383166000908152600560205260408120548290101561057057610002565b61046460035460ff1681565b6103e460028054602060018216156101000260001901909116829004601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260043560056020526000908152604090205481565b6103e4600180546020600282841615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b6103e2600435602435600160a060020a033316600090815260056020526040902054819010156104a157610002565b60806020604435600481810135601f810184900490930284016040526060838152610452948235946024803595606494939101919081908382808284375094965050505050505060006000836006600050600033600160a060020a03168152602001908152602001600020600050600087600160a060020a031681526020019081526020016000206000508190555084905080600160a060020a0316638f4ffcb1338630876040518560e060020a0281526004018085600160a060020a0316815260200184815260200183600160a060020a03168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561036b5780820380516001836020036101000a031916815260200191505b50955050505050506000604051808303816000876161da5a03f11561000257506001979650505050505050565b6007602090815260043560009081526040808220909252602435815220546104529081565b6006602090815260043560009081526040808220909252602435815220546104529081565b005b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156104445780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051918252519081900360200190f35b6060908152602090f35b820191906000526020600020905b81548152906001019060200180831161047c57829003601f168201915b505050505081565b600160a060020a0382166000908152604090205480820110156104c357610002565b806005600050600033600160a060020a03168152602001908152602001600020600082828250540392505081905550806005600050600084600160a060020a0316815260200190815260200160002060008282825054019250508190555081600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600160a060020a03831681526040812054808301101561058f57610002565b600160a060020a038085168083526006602090815260408085203394909416808652938252808520549285526007825280852093855292905290822054830111156105d957610002565b816005600050600086600160a060020a03168152602001908152602001600020600082828250540392505081905550816005600050600085600160a060020a03168152602001908152602001600020600082828250540192505081905550816007600050600086600160a060020a03168152602001908152602001600020600050600033600160a060020a0316815260200190815260200160002060008282825054019250508190555082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3506001939250505056

你可以在EtherScan上看到这些,或者你可以通过打开控制台并运行TokenContract.eth.getCode('YOUR_ADDRESS_HERE_NO_0x_AT_BEGINNING')从以太坊钱包中获得这段代码; Mist和EtherScan都生成相同的代码。

我尝试使用[Browser Solidty]http://chriseth.github.io/browser-solidity/)验证可能有20个不同版本(结合选择或不选择优化),从来没有一次是和Etherscan.io生成的代码一样短,也不是以0x开头.....

以下是使用0.2.1-3ad5e821并选择优化时Browser Solidty和EtherScan为我提供的示例:

606060405260405161092b38038061092b83398101604052805160805160a05160c05160e05193949283019391929081019101600160a060020a03331660009081526005602090815260408220879055600487905581548651838052601f6002600019600185161561010002019093169290920482018390047f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390810193919290918901908390106100d457805160ff19168380011785555b506101049291505b8082111561015d57600081556001016100c0565b828001600101855582156100b8579182015b828111156100b85782518260005055916020019190600101906100e6565b50508160016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061016157805160ff19168380011785555b506101919291506100c0565b5090565b82800160010185558215610151579182015b82811115610151578251826000505591602001919060010190610173565b50506003805460ff19168417905560028054825160008390527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace602060018416156101000260001901909316849004601f90810184900482019386019083901061020e57805160ff19168380011785555b5061023e9291506100c0565b82800160010185558215610202579182015b82811115610202578251826000505591602001919060010190610220565b505050505050506106d8806102536000396000f36060604052361561008d5760e060020a600035046306fdde03811461009557806318160ddd146100f257806323b872dd146100fb578063313ce5671461012d57806354fd4d501461013957806370a082311461019357806395d89b41146101ab578063a9059cbb14610207578063cae9ca5114610236578063dc3080f214610398578063dd62ed3e146103bd575b6103e2610002565b6103e460008054602060026001831615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260045481565b610452600435602435604435600160a060020a0383166000908152600560205260408120548290101561057057610002565b61046460035460ff1681565b6103e460028054602060018216156101000260001901909116829004601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260043560056020526000908152604090205481565b6103e4600180546020600282841615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b6103e2600435602435600160a060020a033316600090815260056020526040902054819010156104a157610002565b60806020604435600481810135601f810184900490930284016040526060838152610452948235946024803595606494939101919081908382808284375094965050505050505060006000836006600050600033600160a060020a03168152602001908152602001600020600050600087600160a060020a031681526020019081526020016000206000508190555084905080600160a060020a0316638f4ffcb1338630876040518560e060020a0281526004018085600160a060020a0316815260200184815260200183600160a060020a03168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561036b5780820380516001836020036101000a031916815260200191505b50955050505050506000604051808303816000876161da5a03f11561000257506001979650505050505050565b6007602090815260043560009081526040808220909252602435815220546104529081565b6006602090815260043560009081526040808220909252602435815220546104529081565b005b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156104445780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051918252519081900360200190f35b6060908152602090f35b820191906000526020600020905b81548152906001019060200180831161047c57829003601f168201915b505050505081565b600160a060020a0382166000908152604090205480820110156104c357610002565b806005600050600033600160a060020a03168152602001908152602001600020600082828250540392505081905550806005600050600084600160a060020a0316815260200190815260200160002060008282825054019250508190555081600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600160a060020a03831681526040812054808301101561058f57610002565b600160a060020a038085168083526006602090815260408085203394909416808652938252808520549285526007825280852093855292905290822054830111156105d957610002565b816005600050600086600160a060020a03168152602001908152602001600020600082828250540392505081905550816005600050600085600160a060020a03168152602001908152602001600020600082828250540192505081905550816007600050600086600160a060020a03168152602001908152602001600020600050600033600160a060020a0316815260200190815260200160002060008282825054019250508190555082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3506001939250505056

所以....它仍然不符合Mist所发送的和EtherScan收到的内容。

在做研究的过程中,我发现EtherChain在验证方面可能会有更好的运气。 然而,我仍然无法获得高于93%的相似性(使用2.1.1版本并优化)。

希望这有所帮助。

||
||

回答发布于 2018-09-10 16:31:25

目前并没有真正简单的方法。 我在试着自己弄清楚;-)

当你在电子中运行开发人员版本时,你始终可以转到文件夹运行mist代码并键入:

node

然后将你带到节点终端,你可以在其中检查你的Solidity版本:

var solc = require('solc')
solc.version()

> '0.2.1-91a6b35f/.-Emscripten/clang/int linked to libethereum-'

理想情况下,我们的目标是让mist在网络上广播源代码和编译器版本,以便像etherchain和etherscan这样的服务可以验证它。

上次我尝试在以太坊提示罐(ethereum tip jar)上验证(我自己部署)的合约时,我只能达到97%的相似度。 我没有机会测试它,但我相信差异在于发送到构造函数的参数,因为变化只发生在文件端。

||
||

回答发布于 2018-09-10 16:31:25

目前并没有真正简单的方法。 我在试着自己弄清楚;-)

当你在电子中运行开发人员版本时,你始终可以转到文件夹运行mist代码并键入:

node

然后将你带到节点终端,你可以在其中检查你的Solidity版本:

var solc = require('solc')
solc.version()

> '0.2.1-91a6b35f/.-Emscripten/clang/int linked to libethereum-'

理想情况下,我们的目标是让mist在网络上广播源代码和编译器版本,以便像etherchain和etherscan这样的服务可以验证它。

上次我尝试在以太坊提示罐(ethereum tip jar)上验证(我自己部署)的合约时,我只能达到97%的相似度。 我没有机会测试它,但我相信差异在于发送到构造函数的参数,因为变化只发生在文件端。

||
||

回答发布于 2018-09-10 16:31:26

Mist/Ethereum Wallet现在有一个内置的编译器——除了教程中的为了教学创建、编译和部署合约的屏幕截图之外,它并不是很好的文档。但是,Mist编译器的版本以及它是否经过优化是很难搞清楚的。

但是,这并不一定能解决你在EtherScan上得到验证的问题。无论我尝试过什么(或尝试了多少次),我都无法获得匹配的代币代码。如果你想和我一起潜水,请参阅此评论的最后。


如果在EtherScan上获得验证对你来说很重要,那么请在此处编写你的Solidity代码,然后使用浏览器Solidity编译它:http//chriseth.github.io/browser-solidity/

然后使用该字节码进行部署。我没有对它进行测试,但它为示例代币合约生成的代码与EtherScan生成的代码相匹配。我猜想EtherScan是使用了相同的基于浏览器的编译器来检查和验证合约。


如果你使用的是Mix IDE/Solidity,则可以通过到(在Mix IDE中)File/Mix/Help->About中来查看Solidity版本。


如果你使用solc/Solidity(命令行界面),你可以使用命令web3.eth.compile,然后生成类似于下面的东西:

contract = eth.compile.solidity(source).test
{
  code: '605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056',
  info: {
    language: 'Solidity',
    languageVersion: '0',
    compilerVersion: '0.9.13',
    abiDefinition: [{
      constant: false,
      inputs: [{
        name: 'a',
        type: 'uint256'
      } ],
      name: 'multiply',
      outputs: [{
        name: 'd',
        type: 'uint256'
      } ],
      type: 'function'
    } ],
    userDoc: {
      methods: {
      }
    },
    developerDoc: {
      methods: {
      }
    },
    source: 'contract test { function multiply(uint a) returns(uint d) { return a * 7; } }'
  }
}

这将编译你的代码并为你提供编译器版本等信息。

更多信息


Optimization-优化是你自己做出的选择。 通过solc,你可以使用--optimize标志。 你可以从此处阅读到有关此神奇Optimization属性的更多信息:Solidity优化程序是如何运行的?( How does the solidity optimizer work?) 我认为Mist正在根据以下事实进行优化:当我在EtherScan上选择“未优化”时,我的相似度为73%,当我选择优化时,我的相似度为93%。


合约测试:

我已经使用Mist v 0.5.2创建了合约https://www.ethereum.org/token#the-code,但没有对代码进行任何更改。

Etherscan.io收到/Mist发送的合约代码如下:

0x6060604052361561008d5760e060020a600035046306fdde03811461009557806318160ddd146100f257806323b872dd146100fb578063313ce5671461012d57806354fd4d501461013957806370a082311461019357806395d89b41146101ab578063a9059cbb14610207578063cae9ca5114610236578063dc3080f214610398578063dd62ed3e146103bd575b6103e2610002565b6103e460008054602060026001831615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260045481565b610452600435602435604435600160a060020a0383166000908152600560205260408120548290101561057057610002565b61046460035460ff1681565b6103e460028054602060018216156101000260001901909116829004601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260043560056020526000908152604090205481565b6103e4600180546020600282841615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b6103e2600435602435600160a060020a033316600090815260056020526040902054819010156104a157610002565b60806020604435600481810135601f810184900490930284016040526060838152610452948235946024803595606494939101919081908382808284375094965050505050505060006000836006600050600033600160a060020a03168152602001908152602001600020600050600087600160a060020a031681526020019081526020016000206000508190555084905080600160a060020a0316638f4ffcb1338630876040518560e060020a0281526004018085600160a060020a0316815260200184815260200183600160a060020a03168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561036b5780820380516001836020036101000a031916815260200191505b50955050505050506000604051808303816000876161da5a03f11561000257506001979650505050505050565b6007602090815260043560009081526040808220909252602435815220546104529081565b6006602090815260043560009081526040808220909252602435815220546104529081565b005b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156104445780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051918252519081900360200190f35b6060908152602090f35b820191906000526020600020905b81548152906001019060200180831161047c57829003601f168201915b505050505081565b600160a060020a0382166000908152604090205480820110156104c357610002565b806005600050600033600160a060020a03168152602001908152602001600020600082828250540392505081905550806005600050600084600160a060020a0316815260200190815260200160002060008282825054019250508190555081600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600160a060020a03831681526040812054808301101561058f57610002565b600160a060020a038085168083526006602090815260408085203394909416808652938252808520549285526007825280852093855292905290822054830111156105d957610002565b816005600050600086600160a060020a03168152602001908152602001600020600082828250540392505081905550816005600050600085600160a060020a03168152602001908152602001600020600082828250540192505081905550816007600050600086600160a060020a03168152602001908152602001600020600050600033600160a060020a0316815260200190815260200160002060008282825054019250508190555082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3506001939250505056

你可以在EtherScan上看到这些,或者你可以通过打开控制台并运行TokenContract.eth.getCode('YOUR_ADDRESS_HERE_NO_0x_AT_BEGINNING')从以太坊钱包中获得这段代码; Mist和EtherScan都生成相同的代码。

我尝试使用[Browser Solidty]http://chriseth.github.io/browser-solidity/)验证可能有20个不同版本(结合选择或不选择优化),从来没有一次是和Etherscan.io生成的代码一样短,也不是以0x开头.....

以下是使用0.2.1-3ad5e821并选择优化时Browser Solidty和EtherScan为我提供的示例:

606060405260405161092b38038061092b83398101604052805160805160a05160c05160e05193949283019391929081019101600160a060020a03331660009081526005602090815260408220879055600487905581548651838052601f6002600019600185161561010002019093169290920482018390047f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390810193919290918901908390106100d457805160ff19168380011785555b506101049291505b8082111561015d57600081556001016100c0565b828001600101855582156100b8579182015b828111156100b85782518260005055916020019190600101906100e6565b50508160016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061016157805160ff19168380011785555b506101919291506100c0565b5090565b82800160010185558215610151579182015b82811115610151578251826000505591602001919060010190610173565b50506003805460ff19168417905560028054825160008390527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace602060018416156101000260001901909316849004601f90810184900482019386019083901061020e57805160ff19168380011785555b5061023e9291506100c0565b82800160010185558215610202579182015b82811115610202578251826000505591602001919060010190610220565b505050505050506106d8806102536000396000f36060604052361561008d5760e060020a600035046306fdde03811461009557806318160ddd146100f257806323b872dd146100fb578063313ce5671461012d57806354fd4d501461013957806370a082311461019357806395d89b41146101ab578063a9059cbb14610207578063cae9ca5114610236578063dc3080f214610398578063dd62ed3e146103bd575b6103e2610002565b6103e460008054602060026001831615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260045481565b610452600435602435604435600160a060020a0383166000908152600560205260408120548290101561057057610002565b61046460035460ff1681565b6103e460028054602060018216156101000260001901909116829004601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260043560056020526000908152604090205481565b6103e4600180546020600282841615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b6103e2600435602435600160a060020a033316600090815260056020526040902054819010156104a157610002565b60806020604435600481810135601f810184900490930284016040526060838152610452948235946024803595606494939101919081908382808284375094965050505050505060006000836006600050600033600160a060020a03168152602001908152602001600020600050600087600160a060020a031681526020019081526020016000206000508190555084905080600160a060020a0316638f4ffcb1338630876040518560e060020a0281526004018085600160a060020a0316815260200184815260200183600160a060020a03168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561036b5780820380516001836020036101000a031916815260200191505b50955050505050506000604051808303816000876161da5a03f11561000257506001979650505050505050565b6007602090815260043560009081526040808220909252602435815220546104529081565b6006602090815260043560009081526040808220909252602435815220546104529081565b005b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156104445780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051918252519081900360200190f35b6060908152602090f35b820191906000526020600020905b81548152906001019060200180831161047c57829003601f168201915b505050505081565b600160a060020a0382166000908152604090205480820110156104c357610002565b806005600050600033600160a060020a03168152602001908152602001600020600082828250540392505081905550806005600050600084600160a060020a0316815260200190815260200160002060008282825054019250508190555081600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600160a060020a03831681526040812054808301101561058f57610002565b600160a060020a038085168083526006602090815260408085203394909416808652938252808520549285526007825280852093855292905290822054830111156105d957610002565b816005600050600086600160a060020a03168152602001908152602001600020600082828250540392505081905550816005600050600085600160a060020a03168152602001908152602001600020600082828250540192505081905550816007600050600086600160a060020a03168152602001908152602001600020600050600033600160a060020a0316815260200190815260200160002060008282825054019250508190555082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3506001939250505056

所以....它仍然不符合Mist所发送的和EtherScan收到的内容。

在做研究的过程中,我发现EtherChain在验证方面可能会有更好的运气。 然而,我仍然无法获得高于93%的相似性(使用2.1.1版本并优化)。

希望这有所帮助。

||
||

回答发布于 2018-09-10 16:31:26

Mist/Ethereum Wallet现在有一个内置的编译器——除了教程中的为了教学创建、编译和部署合约的屏幕截图之外,它并不是很好的文档。但是,Mist编译器的版本以及它是否经过优化是很难搞清楚的。

但是,这并不一定能解决你在EtherScan上得到验证的问题。无论我尝试过什么(或尝试了多少次),我都无法获得匹配的代币代码。如果你想和我一起潜水,请参阅此评论的最后。


如果在EtherScan上获得验证对你来说很重要,那么请在此处编写你的Solidity代码,然后使用浏览器Solidity编译它:http//chriseth.github.io/browser-solidity/

然后使用该字节码进行部署。我没有对它进行测试,但它为示例代币合约生成的代码与EtherScan生成的代码相匹配。我猜想EtherScan是使用了相同的基于浏览器的编译器来检查和验证合约。


如果你使用的是Mix IDE/Solidity,则可以通过到(在Mix IDE中)File/Mix/Help->About中来查看Solidity版本。


如果你使用solc/Solidity(命令行界面),你可以使用命令web3.eth.compile,然后生成类似于下面的东西:

contract = eth.compile.solidity(source).test
{
  code: '605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056',
  info: {
    language: 'Solidity',
    languageVersion: '0',
    compilerVersion: '0.9.13',
    abiDefinition: [{
      constant: false,
      inputs: [{
        name: 'a',
        type: 'uint256'
      } ],
      name: 'multiply',
      outputs: [{
        name: 'd',
        type: 'uint256'
      } ],
      type: 'function'
    } ],
    userDoc: {
      methods: {
      }
    },
    developerDoc: {
      methods: {
      }
    },
    source: 'contract test { function multiply(uint a) returns(uint d) { return a * 7; } }'
  }
}

这将编译你的代码并为你提供编译器版本等信息。

更多信息


Optimization-优化是你自己做出的选择。 通过solc,你可以使用--optimize标志。 你可以从此处阅读到有关此神奇Optimization属性的更多信息:Solidity优化程序是如何运行的?( How does the solidity optimizer work?) 我认为Mist正在根据以下事实进行优化:当我在EtherScan上选择“未优化”时,我的相似度为73%,当我选择优化时,我的相似度为93%。


合约测试:

我已经使用Mist v 0.5.2创建了合约https://www.ethereum.org/token#the-code,但没有对代码进行任何更改。

Etherscan.io收到/Mist发送的合约代码如下:

0x6060604052361561008d5760e060020a600035046306fdde03811461009557806318160ddd146100f257806323b872dd146100fb578063313ce5671461012d57806354fd4d501461013957806370a082311461019357806395d89b41146101ab578063a9059cbb14610207578063cae9ca5114610236578063dc3080f214610398578063dd62ed3e146103bd575b6103e2610002565b6103e460008054602060026001831615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260045481565b610452600435602435604435600160a060020a0383166000908152600560205260408120548290101561057057610002565b61046460035460ff1681565b6103e460028054602060018216156101000260001901909116829004601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260043560056020526000908152604090205481565b6103e4600180546020600282841615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b6103e2600435602435600160a060020a033316600090815260056020526040902054819010156104a157610002565b60806020604435600481810135601f810184900490930284016040526060838152610452948235946024803595606494939101919081908382808284375094965050505050505060006000836006600050600033600160a060020a03168152602001908152602001600020600050600087600160a060020a031681526020019081526020016000206000508190555084905080600160a060020a0316638f4ffcb1338630876040518560e060020a0281526004018085600160a060020a0316815260200184815260200183600160a060020a03168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561036b5780820380516001836020036101000a031916815260200191505b50955050505050506000604051808303816000876161da5a03f11561000257506001979650505050505050565b6007602090815260043560009081526040808220909252602435815220546104529081565b6006602090815260043560009081526040808220909252602435815220546104529081565b005b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156104445780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051918252519081900360200190f35b6060908152602090f35b820191906000526020600020905b81548152906001019060200180831161047c57829003601f168201915b505050505081565b600160a060020a0382166000908152604090205480820110156104c357610002565b806005600050600033600160a060020a03168152602001908152602001600020600082828250540392505081905550806005600050600084600160a060020a0316815260200190815260200160002060008282825054019250508190555081600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600160a060020a03831681526040812054808301101561058f57610002565b600160a060020a038085168083526006602090815260408085203394909416808652938252808520549285526007825280852093855292905290822054830111156105d957610002565b816005600050600086600160a060020a03168152602001908152602001600020600082828250540392505081905550816005600050600085600160a060020a03168152602001908152602001600020600082828250540192505081905550816007600050600086600160a060020a03168152602001908152602001600020600050600033600160a060020a0316815260200190815260200160002060008282825054019250508190555082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3506001939250505056

你可以在EtherScan上看到这些,或者你可以通过打开控制台并运行TokenContract.eth.getCode('YOUR_ADDRESS_HERE_NO_0x_AT_BEGINNING')从以太坊钱包中获得这段代码; Mist和EtherScan都生成相同的代码。

我尝试使用[Browser Solidty]http://chriseth.github.io/browser-solidity/)验证可能有20个不同版本(结合选择或不选择优化),从来没有一次是和Etherscan.io生成的代码一样短,也不是以0x开头.....

以下是使用0.2.1-3ad5e821并选择优化时Browser Solidty和EtherScan为我提供的示例:

606060405260405161092b38038061092b83398101604052805160805160a05160c05160e05193949283019391929081019101600160a060020a03331660009081526005602090815260408220879055600487905581548651838052601f6002600019600185161561010002019093169290920482018390047f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390810193919290918901908390106100d457805160ff19168380011785555b506101049291505b8082111561015d57600081556001016100c0565b828001600101855582156100b8579182015b828111156100b85782518260005055916020019190600101906100e6565b50508160016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061016157805160ff19168380011785555b506101919291506100c0565b5090565b82800160010185558215610151579182015b82811115610151578251826000505591602001919060010190610173565b50506003805460ff19168417905560028054825160008390527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace602060018416156101000260001901909316849004601f90810184900482019386019083901061020e57805160ff19168380011785555b5061023e9291506100c0565b82800160010185558215610202579182015b82811115610202578251826000505591602001919060010190610220565b505050505050506106d8806102536000396000f36060604052361561008d5760e060020a600035046306fdde03811461009557806318160ddd146100f257806323b872dd146100fb578063313ce5671461012d57806354fd4d501461013957806370a082311461019357806395d89b41146101ab578063a9059cbb14610207578063cae9ca5114610236578063dc3080f214610398578063dd62ed3e146103bd575b6103e2610002565b6103e460008054602060026001831615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260045481565b610452600435602435604435600160a060020a0383166000908152600560205260408120548290101561057057610002565b61046460035460ff1681565b6103e460028054602060018216156101000260001901909116829004601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260043560056020526000908152604090205481565b6103e4600180546020600282841615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b6103e2600435602435600160a060020a033316600090815260056020526040902054819010156104a157610002565b60806020604435600481810135601f810184900490930284016040526060838152610452948235946024803595606494939101919081908382808284375094965050505050505060006000836006600050600033600160a060020a03168152602001908152602001600020600050600087600160a060020a031681526020019081526020016000206000508190555084905080600160a060020a0316638f4ffcb1338630876040518560e060020a0281526004018085600160a060020a0316815260200184815260200183600160a060020a03168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561036b5780820380516001836020036101000a031916815260200191505b50955050505050506000604051808303816000876161da5a03f11561000257506001979650505050505050565b6007602090815260043560009081526040808220909252602435815220546104529081565b6006602090815260043560009081526040808220909252602435815220546104529081565b005b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156104445780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051918252519081900360200190f35b6060908152602090f35b820191906000526020600020905b81548152906001019060200180831161047c57829003601f168201915b505050505081565b600160a060020a0382166000908152604090205480820110156104c357610002565b806005600050600033600160a060020a03168152602001908152602001600020600082828250540392505081905550806005600050600084600160a060020a0316815260200190815260200160002060008282825054019250508190555081600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600160a060020a03831681526040812054808301101561058f57610002565b600160a060020a038085168083526006602090815260408085203394909416808652938252808520549285526007825280852093855292905290822054830111156105d957610002565b816005600050600086600160a060020a03168152602001908152602001600020600082828250540392505081905550816005600050600085600160a060020a03168152602001908152602001600020600082828250540192505081905550816007600050600086600160a060020a03168152602001908152602001600020600050600033600160a060020a0316815260200190815260200160002060008282825054019250508190555082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3506001939250505056

所以....它仍然不符合Mist所发送的和EtherScan收到的内容。

在做研究的过程中,我发现EtherChain在验证方面可能会有更好的运气。 然而,我仍然无法获得高于93%的相似性(使用2.1.1版本并优化)。

希望这有所帮助。

||
||

回答发布于 2018-09-10 16:31:25

目前并没有真正简单的方法。 我在试着自己弄清楚;-)

当你在电子中运行开发人员版本时,你始终可以转到文件夹运行mist代码并键入:

node

然后将你带到节点终端,你可以在其中检查你的Solidity版本:

var solc = require('solc')
solc.version()

> '0.2.1-91a6b35f/.-Emscripten/clang/int linked to libethereum-'

理想情况下,我们的目标是让mist在网络上广播源代码和编译器版本,以便像etherchain和etherscan这样的服务可以验证它。

上次我尝试在以太坊提示罐(ethereum tip jar)上验证(我自己部署)的合约时,我只能达到97%的相似度。 我没有机会测试它,但我相信差异在于发送到构造函数的参数,因为变化只发生在文件端。

||
||