本文主要是介绍Etherscan 上传和验证合约源码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
为什么要上传智能合约的代码呢?
- 公开token的源码,增加透明度和投资人的信任度;
- 上传源码后,人们可以在Etherscan查看当前token的源码,同时也可以很方便的看到token的相关信息。
上传代码后,通过源码验证和没有通过源码验证有什么区别?
#合约代码没有通过 Verify Your Contract Source Code的样子
#合约代码通过 Verify Your Contract Source Code的样子
# 下面我们来看看怎么通过验证
先看一下源码验证页面构造
通过上图可以看到,除了构造参数的byteCode外,其他的参数都可以直接拿到。
# 下面我们来看一下怎么获取到构造参数的byteCode.
在Remix编译通过后,点击【Details】获取byteCode信息
初始的byteCode如下:608060405234801561001057600080fd5b506040516102f23803806102f2833981018060405281019080805190602001909291908051820192919050505081600081905550806001908051906020019061005a929190610062565b505050610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b6101dc806101166000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610051578063e1c07999146100e1575b600080fd5b34801561005d57600080fd5b5061006661010c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a657808201518184015260208101905061008b565b50505050905090810190601f1680156100d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100ed57600080fd5b506100f66101aa565b6040518082815260200191505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101a25780601f10610177576101008083540402835291602001916101a2565b820191906000526020600020905b81548152906001019060200180831161018557829003601f168201915b505050505081565b600054815600a165627a7a72305820b9bd0dd3063bd454f741bdc4b7bd61e69382846b2286cf354e302bb5be67720d0029
输入参数后,部署合约得到的byteCode值
注意:部署成功后,控制台会有一条交易信息,点击展开后,即可看到具体的一些部署信息。
添加构造参数的byteCode如下:0x608060405234801561001057600080fd5b506040516102f23803806102f2833981018060405281019080805190602001909291908051820192919050505081600081905550806001908051906020019061005a929190610062565b505050610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b6101dc806101166000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610051578063e1c07999146100e1575b600080fd5b34801561005d57600080fd5b5061006661010c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a657808201518184015260208101905061008b565b50505050905090810190601f1680156100d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100ed57600080fd5b506100f66101aa565b6040518082815260200191505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101a25780601f10610177576101008083540402835291602001916101a2565b820191906000526020600020905b81548152906001019060200180831161018557829003601f168201915b505050505081565b600054815600a165627a7a72305820b9bd0dd3063bd454f741bdc4b7bd61e69382846b2286cf354e302bb5be67720d002900000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000006e5bca0e4b8890000000000000000000000000000000000000000000000000000
与初始的byteCode比较发现两者就多了后面一段字节数据:00000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000006e5bca0e4b8890000000000000000000000000000000000000000000000000000
这一段字节数据就是我们的构造参数{ "uint256 _num": "1000000", "string _name": "张三" }
获得构造参数的byteCode后,回归到我们的 Verify Your Contract Source Code
页面,将上面的那段byteCode粘贴到
最后点击【Verify And Publish】,验证和发布我们的源码。如果成功后,就可以在Etherscan查看你的token的源码和一些可见的数据信息了。
到此,恭喜你已经成功的上传和验证通过你的合约源码了!
作者:DeanDnnn
链接:https://www.jianshu.com/p/56082f942bb3
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
这篇关于Etherscan 上传和验证合约源码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!