Solidity
無法在 etherscan.io 上驗證合約“錯誤!無法生成合約字節碼和 ABI”
我正在嘗試驗證我在 etherscan.io 上部署的契約
但是我收到以下錯誤:
“錯誤!無法生成合約字節碼和 ABI”
我沒有放入 ABI,因為我的建構子沒有任何值或參數。
我究竟做錯了什麼?
以下是我的合約程式碼:
pragma solidity ^0.4.0; // deploying contract on account 0x80A3bA6F52D63aFF73cA582343C2F67046DcEC6f contract PayCheck { //List all the empolyees ethereum payment addresses in an array. address[] employees = [0x9391ea51c338410B6603e38dD14C00a1b218C8d5, 0x9391ea51c338410B6603e38dD14C00a1b218C8d5 ]; //Set a variable that trackes the total recieved to the contract, starting with 0. uint totalReceived = 0; //Create a dictionary that tracks how much as been withdrawn to each ethereum address. mapping (address => uint) withdrawnAmounts; //This function updates the total amount that's been sent to the contract function PayCheck() payable { updateTotal(); } function () payable { updateTotal(); } // This is an internal function that updates the total amount that's been sent to the contract. function updateTotal() internal { totalReceived += msg.value; } //Here is a modifier that ensures only people in the empolyees list that execute the withdraw function. modifier canWidthdraw() { bool contains = false; //A simple for loop that check if they are in the empolyee list before it's aloud to execute the function this modifier is assigned to. for(uint i = 0; i < employees.length; i++) { if(employees[i] == msg.sender) { contains = true; } } require(contains); _; } // Function that calculates what the user can withdraw and to where. function withdraw() canWidthdraw { uint amountAllocated = totalReceived/employees.length; uint amountWithdrawn = withdrawnAmounts[msg.sender]; uint amount = amountAllocated - amountWithdrawn; withdrawnAmounts[msg.sender] = amountWithdrawn + amount; if (amount > 0) { msg.sender.transfer(amount); } } }
您需要選擇編譯器並設置優化以匹配您用於編譯實際部署的字節碼的方法。在這裡,
^
混淆問題,因為它可能是 0.4 或更高。您可以測試您的實際編譯器,但這樣做的方法將取決於您使用什麼。例如,
solc version
或truffle version
。Etherscan 將按照指示編譯粘貼的原始碼,並與它在您指定地址的鏈上實際找到的字節碼進行比較。當有匹配時,它會記錄下來並指出您粘貼的來源是合法的。希望能幫助到你。