foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.33k stars 1.76k forks source link

bug(`forge script`): Multi chain deployment script verify second chain always failed #9357

Open andrew54068 opened 2 days ago

andrew54068 commented 2 days ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.2.0 (896794a 2024-11-10T00:22:42.580055000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

I'm using ledger to deploy to multi-chain and verify, the first one will be verified successfully but the second one will always failed. I'm sure it's not an issue with the Ledger, as it also happens with the private key.

forge script ./script/Deploy.s.sol:Deploy \
--slow \
--multi \
--broadcast \
--ledger \
--mnemonic-indexes ${MNEMONIC_INDEX} \
--verify \
-vvvv
Submitting verification for [src/xxx.sol:xxx] 0x....
Submitted contract for verification:
        Response: `OK`
        GUID: `...jbuqj...`
        URL: https://etherscan.io/address/0x...eb62d474...
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Warning: Verification is still pending... (7 tries remaining)
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
All (1) contracts were verified!
##
Start verification for (1) contracts
Start verifying contract `0x...eb62d474...` deployed on bsc

Submitting verification for [src/xxx.sol:xxx] 0x.....
Error: Encountered an error verifying this contract:
Response: `NOTOK`
Details:
                        `Invalid API Key (#err2)|bsc11`

so I have to use this commend one by one

forge verify-contract \
<contract_address> \
src/x.sol:x \
--chain bsc \
--etherscan-api-key $BASESCAN_API_KEY

And this will succeed, so it means my api key is correct.

This is my foundry.toml

[profile.default]
via_ir = true
src = "src"
out = "out"
libs = ["lib"]

[rpc_endpoints]
mainnet = "${ETHERUM_RPC_URL}"
bsc = "${BSC_RPC_URL}"
base = "${BASE_RPC_URL}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}", chain = "mainnet" }
bsc = { key = "${BSCSCAN_API_KEY}", chain = "bsc" }
base = { key = "${BASESCAN_API_KEY}", chain = "base" }

Not sure where do I do wrong. or did I miss some flag here?

grandizzy commented 1 day ago

@andrew54068 are the forks selected within deploy script using cheatcodes? Side note you can drop the --etherscan-api-key from single commands and use only

forge verify-contract \
<contract_address> \
src/x.sol:x \
--chain bsc 

thank you!

grandizzy commented 16 hours ago

bump @andrew54068 could you please provide sorce code sample to replicate the issue. Thank you!