為什么要上傳智能合約的代碼呢丰涉?
- 公開token的源碼褂乍,增加透明度和投資人的信任度帖渠;
- 上傳源碼后,人們可以在Etherscan查看當(dāng)前token的源碼倔叼,同時也可以很方便的看到token的相關(guān)信息汗唱。
上傳代碼后,通過源碼驗(yàn)證和沒有通過源碼驗(yàn)證有什么區(qū)別丈攒?
#合約代碼沒有通過 Verify Your Contract Source Code的樣子
#合約代碼通過 Verify Your Contract Source Code的樣子
# 下面我們來看看怎么通過驗(yàn)證
先看一下源碼驗(yàn)證頁面構(gòu)造
通過上圖可以看到哩罪,除了構(gòu)造參數(shù)的byteCode外,其他的參數(shù)都可以直接拿到巡验。
# 下面我們來看一下怎么獲取到構(gòu)造參數(shù)的byteCode.
在Remix編譯通過后际插,點(diǎn)擊【Details】獲取byteCode信息
初始的byteCode如下:
608060405234801561001057600080fd5b506040516102f23803806102f2833981018060405281019080805190602001909291908051820192919050505081600081905550806001908051906020019061005a929190610062565b505050610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b6101dc806101166000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610051578063e1c07999146100e1575b600080fd5b34801561005d57600080fd5b5061006661010c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a657808201518184015260208101905061008b565b50505050905090810190601f1680156100d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100ed57600080fd5b506100f66101aa565b6040518082815260200191505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101a25780601f10610177576101008083540402835291602001916101a2565b820191906000526020600020905b81548152906001019060200180831161018557829003601f168201915b505050505081565b600054815600a165627a7a72305820b9bd0dd3063bd454f741bdc4b7bd61e69382846b2286cf354e302bb5be67720d0029
輸入?yún)?shù)后,部署合約得到的byteCode值
注意:部署成功后深碱,控制臺會有一條交易信息腹鹉,點(diǎn)擊展開后,即可看到具體的一些部署信息敷硅。
添加構(gòu)造參數(shù)的byteCode如下:
0x608060405234801561001057600080fd5b506040516102f23803806102f2833981018060405281019080805190602001909291908051820192919050505081600081905550806001908051906020019061005a929190610062565b505050610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b6101dc806101166000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610051578063e1c07999146100e1575b600080fd5b34801561005d57600080fd5b5061006661010c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a657808201518184015260208101905061008b565b50505050905090810190601f1680156100d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100ed57600080fd5b506100f66101aa565b6040518082815260200191505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101a25780601f10610177576101008083540402835291602001916101a2565b820191906000526020600020905b81548152906001019060200180831161018557829003601f168201915b505050505081565b600054815600a165627a7a72305820b9bd0dd3063bd454f741bdc4b7bd61e69382846b2286cf354e302bb5be67720d002900000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000006e5bca0e4b8890000000000000000000000000000000000000000000000000000
與初始的byteCode比較發(fā)現(xiàn)兩者就多了后面一段字節(jié)數(shù)據(jù):00000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000006e5bca0e4b8890000000000000000000000000000000000000000000000000000
這一段字節(jié)數(shù)據(jù)就是我們的構(gòu)造參數(shù)
{ "uint256 _num": "1000000", "string _name": "張三" }
獲得構(gòu)造參數(shù)的byteCode后功咒,回歸到我們的 Verify Your Contract Source Code
頁面,將上面的那段byteCode粘貼到
最后點(diǎn)擊【Verify And Publish】绞蹦,驗(yàn)證和發(fā)布我們的源碼力奋。如果成功后,就可以在Etherscan查看你的token的源碼和一些可見的數(shù)據(jù)信息了幽七。