Wrong message: Invalid API Key
See original GitHub issueDescribe 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
- Operating System: Ubuntu 21.04
- Node version: 16.13.2
- Truffle version: 5.5.13
- truffle-plugin-verify version: 0.5.25
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!
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (3 by maintainers)

Top Related StackOverflow Question
Problem was solved for me too, didn’t change anything in my config.
I use
"truffle-plugin-verify": "^0.5.25".Thank you 🙏
gm all, just dropping in here to mention I gave it a try with truffle verify
0.5.25which 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 ?