Etherscan 上传和验证合约源码

Etherscan 上传和验证合约源码

Etherscan 上传和验证合约源码_第1张图片 DeanDnnn 关注

2018.05.31 11:50* 字数 463 阅读 562评论 7喜欢 1

为什么要上传智能合约的代码呢?

  1. 公开token的源码,增加透明度和投资人的信任度;
  2. 上传源码后,人们可以在Etherscan查看当前token的源码,同时也可以很方便的看到token的相关信息。

上传代码后,通过源码验证和没有通过源码验证有什么区别?

#合约代码没有通过 Verify Your Contract Source Code的样子

Etherscan 上传和验证合约源码_第2张图片

 

#合约代码通过 Verify Your Contract Source Code的样子

Etherscan 上传和验证合约源码_第3张图片

Etherscan 上传和验证合约源码_第4张图片

# 下面我们来看看怎么通过验证

先看一下源码验证页面构造

 

Etherscan 上传和验证合约源码_第5张图片

通过上图可以看到,除了构造参数的byteCode外,其他的参数都可以直接拿到。

# 下面我们来看一下怎么获取到构造参数的byteCode.

在Remix编译通过后,点击【Details】获取byteCode信息

Etherscan 上传和验证合约源码_第6张图片

初始的byteCode如下:
608060405234801561001057600080fd5b506040516102f23803806102f2833981018060405281019080805190602001909291908051820192919050505081600081905550806001908051906020019061005a929190610062565b505050610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b6101dc806101166000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610051578063e1c07999146100e1575b600080fd5b34801561005d57600080fd5b5061006661010c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a657808201518184015260208101905061008b565b50505050905090810190601f1680156100d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100ed57600080fd5b506100f66101aa565b6040518082815260200191505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101a25780601f10610177576101008083540402835291602001916101a2565b820191906000526020600020905b81548152906001019060200180831161018557829003601f168201915b505050505081565b600054815600a165627a7a72305820b9bd0dd3063bd454f741bdc4b7bd61e69382846b2286cf354e302bb5be67720d0029

输入参数后,部署合约得到的byteCode值

注意:部署成功后,控制台会有一条交易信息,点击展开后,即可看到具体的一些部署信息。

Etherscan 上传和验证合约源码_第7张图片

添加构造参数的byteCode如下:
0x608060405234801561001057600080fd5b506040516102f23803806102f2833981018060405281019080805190602001909291908051820192919050505081600081905550806001908051906020019061005a929190610062565b505050610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b6101dc806101166000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610051578063e1c07999146100e1575b600080fd5b34801561005d57600080fd5b5061006661010c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a657808201518184015260208101905061008b565b50505050905090810190601f1680156100d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100ed57600080fd5b506100f66101aa565b6040518082815260200191505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101a25780601f10610177576101008083540402835291602001916101a2565b820191906000526020600020905b81548152906001019060200180831161018557829003601f168201915b505050505081565b600054815600a165627a7a72305820b9bd0dd3063bd454f741bdc4b7bd61e69382846b2286cf354e302bb5be67720d002900000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000006e5bca0e4b8890000000000000000000000000000000000000000000000000000

与初始的byteCode比较发现两者就多了后面一段字节数据:00000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000006e5bca0e4b8890000000000000000000000000000000000000000000000000000

这一段字节数据就是我们的构造参数
{ "uint256 _num": "1000000", "string _name": "张三" }

获得构造参数的byteCode后,回归到我们的 Verify Your Contract Source Code
页面,将上面的那段byteCode粘贴到

Etherscan 上传和验证合约源码_第8张图片

 

最后点击【Verify And Publish】,验证和发布我们的源码。如果成功后,就可以在Etherscan查看你的token的源码和一些可见的数据信息了。

到此,恭喜你已经成功的上传和验证通过你的合约源码了!

你可能感兴趣的:(区块链)