Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verifying via Script causes error #6192

Closed
2 tasks done
BrennerSpear opened this issue Nov 1, 2023 · 3 comments
Closed
2 tasks done

Verifying via Script causes error #6192

BrennerSpear opened this issue Nov 1, 2023 · 3 comments
Labels
T-bug Type: bug

Comments

@BrennerSpear
Copy link

BrennerSpear commented Nov 1, 2023

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (94ae897 2023-10-31T00:17:29.299689000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

I have a script that works to deploy+verify a contract. it calls this deploy.s.sol script

deploy_contract() {
    source .env

    contract_line=$(grep -o 'contract.*is Script' script/deploy.s.sol)
    contract_name=$(echo $contract_line | cut -d " " -f 2)

    if [ "$1" = 'mainnet' ]
    then
        rpc_url=$MAINNET_RPC_URL
        private_key=$MAINNET_PRIVATE_KEY
        scan_key=$ETHERSCAN_API_KEY
        chain_info=""
        # verifier_url=""
    elif [ "$1" = 'base' ]
    then
        rpc_url=$BASE_RPC_URL
        private_key=$BASE_PRIVATE_KEY
        scan_key=$BASESCAN_API_KEY
        chain_info="--chain-id 8453"
        # verifier_url="--verifier-url https://api.basescan.org/api"
    else
        rpc_url=$SEPOLIA_RPC_URL
        private_key=$SEPOLIA_PRIVATE_KEY
        scan_key=$ETHERSCAN_API_KEY
        chain_info=""
        # verifier_url=""
    fi

    if [[ $# -gt 1 ]]; then
        gas_price=$(($2 * 1000000000))
        gas_args="--with-gas-price $gas_price"
    else
        gas_args=""
    fi

    forge_args="--rpc-url $rpc_url --private-key $private_key --etherscan-api-key $scan_key $gas_args $chain_info"
    deploy_command="forge script script/deploy.s.sol:$contract_name --broadcast $forge_args -vvvv"
    verify_command="forge script script/deploy.s.sol:$contract_name $forge_args --verify -vvvv --resume"

    eval $deploy_command

    deployment_successful=false
    while [ "$deployment_successful" = false ]
    do
        eval $verify_command
        if [ $? -eq 0 ]
        then
            deployment_successful=true
        else
            sleep 2
        fi
    done
}

If I just deploy the contract, that works too.

If I try to verify the contract I just deployed that hasn't been verified yet, it does not work. I try this by running the same script up there, but with eval $deploy_command commented out

    ...

    forge_args="--rpc-url $rpc_url --private-key $private_key --etherscan-api-key $scan_key $gas_args $chain_info"
    # deploy_command="forge script script/deploy.s.sol:$contract_name --broadcast $forge_args -vvvv"
    verify_command="forge script script/deploy.s.sol:$contract_name $forge_args --verify --resume -vvvv"

    # eval $deploy_command

    deployment_successful=false
    while [ "$deployment_successful" = false ]
    do
        eval $verify_command
        if [ $? -eq 0 ]
        then
            deployment_successful=true
        else
            sleep 2
        fi
    done

This is the error I get

~/repos/block-lander main| ❯ deploy_contract 
[⠊] Compiling...
No files changed, compilation skipped


==========================

ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.
Total Paid: 0.00616315502465262 ETH (2054385 gas * avg 3.000000012 gwei)
##
Start verification for (1) contracts
Start verifying contract `0x640505112ccf6C3a0D7a65ce8548FF42A96FBd47` deployed on sepolia

Transactions saved to: /Users/brenner/repos/block-lander/broadcast/deploy.s.sol/11155111/run-latest.json

Sensitive values saved to: /Users/brenner/repos/block-lander/cache/deploy.s.sol/11155111/run-latest.json

Error:
expected value at line 1 column 1

If you were trying to resume or verify a multi chain deployment, add `--multi` to your command invocation.


Easiest steps to full repro would be:

~/ > gh repo clone metagame-xyz/block-lander
~/ > cd block-lander
~/block-lander > touch .env
~/block-lander > foundryup

Add the deploy_contract() bash function to your .zshrc or similar. comment out the while do section
open a new window or source your .zshrc file
add the following to your .env file

SEPOLIA_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/your-project-key"
ETHERSCAN_API_KEY="your_etherscan_api_key"
SEPOLIA_PRIVATE_KEY="your_private_key_to_deploy_with"
~/block-lander > deploy_contract

the contract should be deployed to sepolia
comment out eval $deploy_command
comment back in the while do section
open a new window or source your .zshrc file

~/block-lander > deploy_contract

at this point, you should get the same error

@BrennerSpear BrennerSpear added the T-bug Type: bug label Nov 1, 2023
@gakonst gakonst added this to Foundry Nov 1, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Nov 1, 2023
@Evalir Evalir changed the title Verifying via Script causing application panic (crash) Verifying via Script causes error Nov 1, 2023
@BrennerSpear
Copy link
Author

Error: expected value at line 1 column 1

Might just be a non-helpful error from Etherscan / Basescan when there's an issue, like when the API key is incorrect.

Even when you're uploading to Base, it looks for ETHERSCAN_API_KEY. If I'm verifying on Base, I would expect it to look for BASESCAN_API_KEY since the two of them are different api keys

@GopherJ
Copy link

GopherJ commented Nov 28, 2023

same error

@zerosnacks
Copy link
Member

zerosnacks commented Jul 4, 2024

Error: expected value at line 1 column 1

Might just be a non-helpful error from Etherscan / Basescan when there's an issue, like when the API key is incorrect.

Even when you're uploading to Base, it looks for ETHERSCAN_API_KEY. If I'm verifying on Base, I would expect it to look for BASESCAN_API_KEY since the two of them are different api keys

I assume this is related to #7466 + #7699

Closing this ticket in favor of those two. The current way ETHERSCAN_API_KEY is handled is far from ideal (both in Foundry and that Etherscan requires a different API key for every chain).

@zerosnacks zerosnacks closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2024
@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Archived in project
Development

No branches or pull requests

3 participants