之前发布合约的时候都没有注意到这个问题,我也是最近在Etherscan浏览器查看自己合约的时候才发现的这个问题,于是就开始解决一下呗。我看了几篇博客,我认为下面这一篇就讲的很详细。
//www.greatytc.com/p/56082f942bb3
细节我就不多说了,我说说其中比较关键的一些地方,以及大家比较容易犯错的地方吧。
大家先来看看,没有验证过代码的合约是这样的
在Remix编译通过后,点击【Details】获取byteCode信息
Details-------> ByteCode----->object
注意:这里是编译刚通过的时候就要去获取这个ByteCode,而不是等到Run那里填参数之后。
60806040526002805460ff1916601217905534801561001d57600080fd5b50604051610a15380380610a1583398101604090815281516020808401518385015160025460ff16600a0a84026003819055600160a060020a0333166000908152600485529586205590850180519395909491019261007e9285019061009b565b50805161009290600190602084019061009b565b50505050610136565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100dc57805160ff1916838001178555610109565b82800160010185558215610109579182015b828111156101095782518255916020019190600101906100ee565b50610115929150610119565b5090565b61013391905b80821115610115576000815560010161011f565b90565b6108d0806101456000396000f3006080604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100be578063095ea7b31461014857806318160ddd1461018057806323b872dd146101a7578063313ce567146101d157806342966c68146101fc57806370a082311461021457806379cc67901461023557806395d89b4114610259578063a9059cbb1461026e578063cae9ca5114610294578063dd62ed3e146102fd575b600080fd5b3480156100ca57600080fd5b506100d3610324565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561010d5781810151838201526020016100f5565b50505050905090810190601f16801561013a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015457600080fd5b5061016c600160a060020a03600435166024356103b2565b604080519115158252519081900360200190f35b34801561018c57600080fd5b506101956103e2565b60408051918252519081900360200190f35b3480156101b357600080fd5b5061016c600160a060020a03600435811690602435166044356103e8565b3480156101dd57600080fd5b506101e661045f565b6040805160ff9092168252519081900360200190f35b34801561020857600080fd5b5061016c600435610468565b34801561022057600080fd5b50610195600160a060020a03600435166104f2565b34801561024157600080fd5b5061016c600160a060020a0360043516602435610504565b34801561026557600080fd5b506100d36105e0565b34801561027a57600080fd5b50610292600160a060020a036004351660243561063a565b005b3480156102a057600080fd5b50604080516020600460443581810135601f810184900484028501840190955284845261016c948235600160a060020a03169460248035953695946064949201919081908401838280828437509497506106499650505050505050565b34801561030957600080fd5b50610195600160a060020a0360043581169060243516610780565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103aa5780601f1061037f576101008083540402835291602001916103aa565b820191906000526020600020905b81548152906001019060200180831161038d57829003601f168201915b505050505081565b600160a060020a033381166000908152600560209081526040808320938616835292905220819055600192915050565b60035481565b600160a060020a0380841660009081526005602090815260408083203390941683529290529081205482111561041d57600080fd5b600160a060020a038085166000908152600560209081526040808320339094168352929052208054839003905561045584848461079d565b5060019392505050565b60025460ff1681565b600160a060020a03331660009081526004602052604081205482111561048d57600080fd5b600160a060020a03331660008181526004602090815260409182902080548690039055600380548690039055815185815291517fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca59281900390910190a2506001919050565b60046020526000908152604090205481565b600160a060020a03821660009081526004602052604081205482111561052957600080fd5b600160a060020a038084166000908152600560209081526040808320339094168352929052205482111561055c57600080fd5b600160a060020a038084166000818152600460209081526040808320805488900390556005825280832033909516835293815290839020805486900390556003805486900390558251858152925191927fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5929081900390910190a250600192915050565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103aa5780601f1061037f576101008083540402835291602001916103aa565b61064533838361079d565b5050565b60008361065681856103b2565b156107785780600160a060020a0316638f4ffcb1338630876040518563ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004018085600160a060020a0316600160a060020a0316815260200184815260200183600160a060020a0316600160a060020a0316815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561070c5781810151838201526020016106f4565b50505050905090810190601f1680156107395780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561075b57600080fd5b505af115801561076f573d6000803e3d6000fd5b50505050600191505b509392505050565b600560209081526000928352604080842090915290825290205481565b6000600160a060020a03831615156107b457600080fd5b600160a060020a0384166000908152600460205260409020548211156107d957600080fd5b600160a060020a038316600090815260046020526040902054828101116107ff57600080fd5b50600160a060020a038083166000818152600460209081526040808320805495891680855282852080548981039091559486905281548801909155815187815291519390950194927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a3600160a060020a0380841660009081526004602052604080822054928716825290205401811461089e57fe5b505050505600a165627a7a723058202fcf433c82780039ff26c6a0f0f297aee8999f119942eed8a2afb54bb1e35aa30029
输入构造参数,部署合约之后得到
60806040526002805460ff1916601217905534801561001d57600080fd5b50604051610a15380380610a1583398101604090815281516020808401518385015160025460ff16600a0a84026003819055600160a060020a0333166000908152600485529586205590850180519395909491019261007e9285019061009b565b50805161009290600190602084019061009b565b50505050610136565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100dc57805160ff1916838001178555610109565b82800160010185558215610109579182015b828111156101095782518255916020019190600101906100ee565b50610115929150610119565b5090565b61013391905b80821115610115576000815560010161011f565b90565b6108d0806101456000396000f3006080604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100be578063095ea7b31461014857806318160ddd1461018057806323b872dd146101a7578063313ce567146101d157806342966c68146101fc57806370a082311461021457806379cc67901461023557806395d89b4114610259578063a9059cbb1461026e578063cae9ca5114610294578063dd62ed3e146102fd575b600080fd5b3480156100ca57600080fd5b506100d3610324565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561010d5781810151838201526020016100f5565b50505050905090810190601f16801561013a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015457600080fd5b5061016c600160a060020a03600435166024356103b2565b604080519115158252519081900360200190f35b34801561018c57600080fd5b506101956103e2565b60408051918252519081900360200190f35b3480156101b357600080fd5b5061016c600160a060020a03600435811690602435166044356103e8565b3480156101dd57600080fd5b506101e661045f565b6040805160ff9092168252519081900360200190f35b34801561020857600080fd5b5061016c600435610468565b34801561022057600080fd5b50610195600160a060020a03600435166104f2565b34801561024157600080fd5b5061016c600160a060020a0360043516602435610504565b34801561026557600080fd5b506100d36105e0565b34801561027a57600080fd5b50610292600160a060020a036004351660243561063a565b005b3480156102a057600080fd5b50604080516020600460443581810135601f810184900484028501840190955284845261016c948235600160a060020a03169460248035953695946064949201919081908401838280828437509497506106499650505050505050565b34801561030957600080fd5b50610195600160a060020a0360043581169060243516610780565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103aa5780601f1061037f576101008083540402835291602001916103aa565b820191906000526020600020905b81548152906001019060200180831161038d57829003601f168201915b505050505081565b600160a060020a033381166000908152600560209081526040808320938616835292905220819055600192915050565b60035481565b600160a060020a0380841660009081526005602090815260408083203390941683529290529081205482111561041d57600080fd5b600160a060020a038085166000908152600560209081526040808320339094168352929052208054839003905561045584848461079d565b5060019392505050565b60025460ff1681565b600160a060020a03331660009081526004602052604081205482111561048d57600080fd5b600160a060020a03331660008181526004602090815260409182902080548690039055600380548690039055815185815291517fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca59281900390910190a2506001919050565b60046020526000908152604090205481565b600160a060020a03821660009081526004602052604081205482111561052957600080fd5b600160a060020a038084166000908152600560209081526040808320339094168352929052205482111561055c57600080fd5b600160a060020a038084166000818152600460209081526040808320805488900390556005825280832033909516835293815290839020805486900390556003805486900390558251858152925191927fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5929081900390910190a250600192915050565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103aa5780601f1061037f576101008083540402835291602001916103aa565b61064533838361079d565b5050565b60008361065681856103b2565b156107785780600160a060020a0316638f4ffcb1338630876040518563ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004018085600160a060020a0316600160a060020a0316815260200184815260200183600160a060020a0316600160a060020a0316815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561070c5781810151838201526020016106f4565b50505050905090810190601f1680156107395780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561075b57600080fd5b505af115801561076f573d6000803e3d6000fd5b50505050600191505b509392505050565b600560209081526000928352604080842090915290825290205481565b6000600160a060020a03831615156107b457600080fd5b600160a060020a0384166000908152600460205260409020548211156107d957600080fd5b600160a060020a038316600090815260046020526040902054828101116107ff57600080fd5b50600160a060020a038083166000818152600460209081526040808320805495891680855282852080548981039091559486905281548801909155815187815291519390950194927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a3600160a060020a0380841660009081526004602052604080822054928716825290205401811461089e57fe5b505050505600a165627a7a723058202fcf433c82780039ff26c6a0f0f297aee8999f119942eed8a2afb54bb1e35aa300290000000000000000000000000000000000000000000000000000000000000834000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000074d79546f6b656e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024d54000000000000000000000000000000000000000000000000000000000000
注意:添加构造参数,部署和鱼成功之后与初始的byteCode比较发现两者就多了后面一段字节数据:
0000000000000000000000000000000000000000000000000000000000000834000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000074d79546f6b656e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024d54000000000000000000000000000000000000000000000000000000000000
这一段字节数据就是我们的构造参数的byteCode
{ "uint256 initialSupply": "2100", "string tokenName": "MyToken", "string tokenSymbol": "MT" }
我就在这里犯过错,之前一直没找到构造参数的byteCode,大家务必按照步骤来,不然后面通不过。
借上面这篇文章的上传源码的图说明几点。
第一:上面获取到的构造参数的byteCode复制到最下面的那个框中就行(切记按照步骤,我就踩过坑)
第二:编译版本不是指你solidity合约代码中的版本,而是如图所示的这个(这里也踩过坑)
验证成功之后的页面大概是这样的