Solidity
ABI 和合約原始碼在 etherscan 的智能合約上不可見
我最近在乙太坊 rinkeby 網路上發布了一份小型彩票合約。合約已成功部署,但我無法在 Etherscan 門戶上看到合約原始碼和 ABI。下面是地址
https://rinkeby.etherscan.io/address/0xa19Ea5690dD32BFf3081cB0d81f91170AD859E0C#code
我的培訓小組的其他人部署了他們的程式碼,他們得到了 ABI 和其他詳細資訊。下面是網址
https://rinkeby.etherscan.io/address/0xc09eb46ce7A8b32F4339390cB94A3568C20eCaa9#code
下面是 Solidity 程式碼。
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; contract Lottery{ address payable public manager; address payable[] public players; constructor() { manager = payable(msg.sender); } function enter() public payable{ require (msg.value > 0.01 ether); players.push(payable(msg.sender)); } function random_num() private view returns (uint){ return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players))); } function pick_winner() public restricted_func { uint index = random_num() % players.length; players[index].transfer(address(this).balance); players = new address payable[](0); } function get_list_players() public view returns(address payable[] memory) { return players; } modifier restricted_func{ require (msg.sender == manager); _; } }
下面是我的 Deploy.js
const HDWalletProvider = require('@truffle/hdwallet-provider'); const Web3 = require('web3'); const { abi, evm } = require('./compile'); console.log(abi); provider = new HDWalletProvider( "my secret code phrase", "https://rinkeby.infura.io/v3/infura_key" ); const web3 = new Web3(provider); const deploy = async () => { const accounts = await web3.eth.getAccounts(); console.log('Attempting to deploy from account', accounts[0]); const result = await new web3.eth.Contract(abi) .deploy({ data: evm.bytecode.object }) .send({ gas: '1000000', from: accounts[0] }); console.log(abi); console.log('Contract deployed to', result.options.address); provider.engine.stop(); }; deploy();
有人可以幫我理解為什麼嗎?提前謝謝了!!
有時 Etherscan 可能會辨識出類似的契約,這可能是您的合作夥伴已經看到契約的 ABI 的原因。您可以通過在https://rinkeby.etherscan.io/verifyContract上自己驗證契約來手動為您的契約實現這一點。