matter-labs / foundry-zksync

Fork of Foundry tailored for zkSync environment
Apache License 2.0
299 stars 130 forks source link

Error with contract verification on etherscan #597

Closed uF4No closed 1 month ago

uF4No commented 1 month ago

Component

Forge

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

What version of Foundry are you on?

forge 0.0.2 (46d9f92 2024-09-30T00:36:58.923333000Z)

What command(s) is the bug in?

forge verify-contract

Operating System

macOS (Apple Silicon)

Describe the bug

I'm trying to verify a basic ERC20 token contract deployed to ZKsync Sepolia testnet.

Contract was deployed with forge create --rpc-url https://sepolia.era.zksync.dev --private-key MY_PRIVATE_KEY contracts/MyToken.sol:MyToken --constructor-args "Yadayada" "YDD" --zksync

Contract deployed to 0x9602866f8919f5d781967Cff6e5467049A8C5a89.

I added the etherscan config to the foundry.toml file:

[etherscan]
zksyncTestnet = { key = "MY_ETHERSCAN_API_KEY", url = "https://api-sepolia-era.zksync.network/api", chain = 300 }

And tried with the following command:

forge verify-contract 0x9602866f8919f5d781967Cff6e5467049A8C5a89 contracts/MyToken.sol:MyToken --constructor-args 000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000008596164617961646100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035944440000000000000000000000000000000000000000000000000000000000 --chain-id 300 --watch --zksync

(not that constructor args are encoded)

I get the following output:

Start verifying contract `0x9602866f8919f5d781967Cff6e5467049A8C5a89` deployed on zksync-testnet

Submitting verification for [contracts/MyToken.sol:MyToken] 0x9602866f8919f5d781967Cff6e5467049A8C5a89.

Submitting verification for [contracts/MyToken.sol:MyToken] 0x9602866f8919f5d781967Cff6e5467049A8C5a89.

Submitting verification for [contracts/MyToken.sol:MyToken] 0x9602866f8919f5d781967Cff6e5467049A8C5a89.

Submitting verification for [contracts/MyToken.sol:MyToken] 0x9602866f8919f5d781967Cff6e5467049A8C5a89.

Submitting verification for [contracts/MyToken.sol:MyToken] 0x9602866f8919f5d781967Cff6e5467049A8C5a89.

Submitting verification for [contracts/MyToken.sol:MyToken] 0x9602866f8919f5d781967Cff6e5467049A8C5a89.
Error: 
Etherscan could not detect the deployment.

I've been able to verify ZKsync contracts deployed to etherscan with forge verify-contract before, so not sure what the issue could be.

Jrigada commented 1 month ago

Hey Antonio! Thanks for raising this issue. I tried this morning with a couple of contracts of mine and I was able to verify them from my end. I tried with two custom tokens here:

The command I use was this

forge verify-contract 0xbA3bF88220daC494C33c61cfc26c67A750F61693 src/MyToken.sol:TestToken --constructor-args $(cast abi-encode "constructor(string memory,string memory)" "JUAN" "ASD" ) --rpc-url https://sepolia.era.zksync.dev/ --chain-id 300 --watch --zksync -e {API_KEY}

I saw the exact same error you got once today (the first contract I tried) and after retrying it worked and I didn't get the error again. We were facing intermittent RPC issues before as well. Let me know if this helps and if this occurs again. If you have the contract I can try it from my end also.

uF4No commented 1 month ago

hey @Jrigada yeah, looks like an intermitent RPC issue. I managed to verify with the exact same script after a couple of times.