rkalis / truffle-plugin-verify

✅ Verify your smart contracts on Etherscan from the Truffle CLI
https://kalis.me/verify-truffle-smart-contracts-etherscan/
MIT License
467 stars 130 forks source link

Wrong message: Invalid API Key #167

Closed gsierroqx closed 1 year ago

gsierroqx commented 2 years ago

Describe the bug

I am working with Avalanche testnet and trying to verify smart contracts however the answer that I am getting is: "Invalid API Key". I run the verification once again using --debug. Snowtrace is responding with the provided apikey to the HTTP requests so I guess the apikey is not the problem.

Steps To Reproduce

My last attempt was using metacoin example from truffle, same steps described by Avalanche documentation:

https://docs.avax.network/dapps/smart-contracts/verify-smart-contracts-with-truffle-verify/

Environment information

truffle-config.js content:

const HDWalletProvider = require("@truffle/hdwallet-provider"); const { apikey, mnemonic } = require("./.env.json");

module.exports = { plugins: [ 'truffle-plugin-verify' ], api_keys: { snowtrace: apikey }, networks: { fuji: { provider: () => new HDWalletProvider(mnemonic, https://api.avax-test.network/ext/bc/C/rpc), network_id: 43113, timeoutBlocks: 200, confirmations: 5 } } };

Debug output

npx truffle run verify ConvertLib MetaCoin --network fuji --debugDEBUG logging is turned ON Running truffle-plugin-verify v0.5.25 Retrieving network's network ID & chain ID Verifying ConvertLib Reading artifact file at /home/gsierro/Data/workspace/Avalanche/MetaCoin/build/contracts/ConvertLib.json Retrieving constructor parameters from https://api-testnet.snowtrace.io/api?apiKey=[XXXXX]&module=account&action=txlist&address=0x2b1330Be824d7d4018ef9b909f679Fba3Dc1Dff0&page=1&sort=asc&offset=1 Constructor parameters retrieved: 0x Sending verify request with POST arguments: { "apikey": "[XXXXX]", "module": "contract", "action": "verifysourcecode", "contractaddress": "0x2b1330Be824d7d4018ef9b909f679Fba3Dc1Dff0", "sourceCode": "{\"language\":\"Solidity\",\"sources\":{\"/contracts/ConvertLib.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\npragma solidity >=0.4.25 <0.7.0;\n\nlibrary ConvertLib{\n\tfunction convert(uint amount,uint conversionRate) public pure returns (uint convertedAmount)\n\t{\n\t\treturn amount conversionRate;\n\t}\n}\n\"}},\"settings\":{\"remappings\":[],\"optimizer\":{\"enabled\":false,\"runs\":200},\"evmVersion\":\"istanbul\",\"libraries\":{}}}", "codeformat": "solidity-standard-json-input", "contractname": "/contracts/ConvertLib.sol:ConvertLib", "compilerversion": "v0.5.16+commit.9c3226ce", "constructorArguements": "" } Invalid API Key Verifying MetaCoin Reading artifact file at /home/gsierro/Data/workspace/Avalanche/MetaCoin/build/contracts/MetaCoin.json Retrieving constructor parameters from https://api-testnet.snowtrace.io/api?apiKey=[XXXXX]&module=account&action=txlist&address=0xAD6380E56FE1D6d4Cd8010459958fD8f8682Bd0e&page=1&sort=asc&offset=1 Constructor parameters retrieved: 0x Reading artifact file at /home/gsierro/Data/workspace/Avalanche/MetaCoin/build/contracts/ConvertLib.json Sending verify request with POST arguments: { "apikey": "[XXXXX]", "module": "contract", "action": "verifysourcecode", "contractaddress": "0xAD6380E56FE1D6d4Cd8010459958fD8f8682Bd0e", "sourceCode": "{\"language\":\"Solidity\",\"sources\":{\"/contracts/MetaCoin.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\npragma solidity >=0.4.25 <0.7.0;\n\nimport \\"./ConvertLib.sol\\";\n\n// This is just a simple example of a coin-like contract.\n// It is not standards compatible and cannot be expected to talk to other\n// coin/token contracts. If you want to create a standards-compliant\n// token, see: https://github.com/ConsenSys/Tokens. Cheers!\n\ncontract MetaCoin {\n\tmapping (address => uint) balances;\n\n\tevent Transfer(address indexed _from, address indexed _to, uint256 _value);\n\n\tconstructor() public {\n\t\tbalances[tx.origin] = 10000;\n\t}\n\n\tfunction sendCoin(address receiver, uint amount) public returns(bool sufficient) {\n\t\tif (balances[msg.sender] < amount) return false;\n\t\tbalances[msg.sender] -= amount;\n\t\tbalances[receiver] += amount;\n\t\temit Transfer(msg.sender, receiver, amount);\n\t\treturn true;\n\t}\n\n\tfunction getBalanceInEth(address addr) public view returns(uint){\n\t\treturn ConvertLib.convert(getBalance(addr),2);\n\t}\n\n\tfunction getBalance(address addr) public view returns(uint) {\n\t\treturn balances[addr];\n\t}\n}\n\"},\"/contracts/ConvertLib.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\npragma solidity >=0.4.25 <0.7.0;\n\nlibrary ConvertLib{\n\tfunction convert(uint amount,uint conversionRate) public pure returns (uint convertedAmount)\n\t{\n\t\treturn amount conversionRate;\n\t}\n}\n\"}},\"settings\":{\"remappings\":[],\"optimizer\":{\"enabled\":false,\"runs\":200},\"evmVersion\":\"istanbul\",\"libraries\":{\"/contracts/ConvertLib.sol\":{\"ConvertLib\":\"0x2b1330Be824d7d4018ef9b909f679Fba3Dc1Dff0\"}}}}", "codeformat": "solidity-standard-json-input", "contractname": "/contracts/MetaCoin.sol:MetaCoin", "compilerversion": "v0.5.16+commit.9c3226ce", "constructorArguements": "" } Invalid API Key

Thanks for your help!

DavidSparker0417 commented 2 years ago

I'm faced the same issue. I would appreciate someone helping to point it out.

minimoz commented 2 years ago

Exactly the same issue on my end.

rkalis commented 2 years ago

The plugin relays the error message returned from the Snowtrace API, so it is being reported as being an invalid API key. @Enigmatic331, do you know if there are any known issues with Snowtrace API keys?

minimoz commented 2 years ago

Anyone has solved this yet? I confirm that my Snowtrace API key works with the cURL command

0xV4L3NT1N3 commented 2 years ago

gm all, just dropping in here to mention I gave it a try with truffle verify 0.5.25 which didn't output any errors or invalid keys for me.

@gsierroqx can your API Key be used to call any other endpoints from SnowTrace's docs ?

gsierroqx commented 2 years ago

Yes, see bellow: https://api-testnet.snowtrace.io/api?module=account&action=balance&address=0x9BD63e687a5390D5dEA6ca750B83EaaBc74C8622&tag=latest&apikey=XXXX

{ "status": "1", "message": "OK", "result": "1969088475000000000" }

minimoz commented 2 years ago

Problem was solved for me too, didn't change anything in my config.

I use "truffle-plugin-verify": "^0.5.25".

Thank you 🙏

rkalis commented 2 years ago

Does using 0.5.25 fix the issue for everyone? Then I'll have to figure out what happened in the latest version that broke things.

rkalis commented 1 year ago

I'm closing this issue due to inactivity and being unable to reproduce. If this issue persists for anyone here, please re-open the issue with a small repo where it can be reproduced.