smartcontractkit / full-blockchain-solidity-course-py

Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
MIT License
10.8k stars 2.9k forks source link

Lesson 13, API error while deploying contracts to kovan #588

Closed DieKant closed 2 years ago

DieKant commented 2 years ago

Hi

I tried to upload TokenFarm and DappToken on kovan but I'm getting this error on the terminal

`Running 'scripts\deploy.py::main'...
Transaction sent: 0xac25cec120ae5c7f1d4d100f4b3d75425a16f3ef2b09f0b5fd20a886854e8a7a
  Gas price: 2.500000007 gwei   Gas limit: 702941   Nonce: 27
  DappToken.constructor confirmed   Block: 28803854   Gas used: 639038 (90.91%)
  DappToken deployed at: 0xcCe6cbc8FaF84e8Ed6DEcC662A39D49dD60673af

Transaction sent: 0x7f50b670ce1624e1b84839e9b9fc0af502e98b93e0e3832af2009fb7a0c4db5b
  Gas price: 2.500000007 gwei   Gas limit: 1075353   Nonce: 28
  TokenFarm.constructor confirmed   Block: 28803856   Gas used: 977594 (90.91%)
  TokenFarm deployed at: 0xCa4C5019410Cdd562f1B69568A6063B376c297E0

Waiting for https://api-kovan.etherscan.io/api to process contract...
  File "C:\Users\Fedro\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\_cli\run.py", line 50, in main
    return_value, frame = run(
  File "C:\Users\Fedro\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\project\scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File ".\scripts\deploy.py", line 42, in main
    deploy_token_farm_and_dapp_token()
  File ".\scripts\deploy.py", line 10, in deploy_token_farm_and_dapp_token
    token_farm = TokenFarm.deploy(
  File "C:\Users\Fedro\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py", line 524, in __call__
    return tx["from"].deploy(
  File "C:\Users\Fedro\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py", line 557, in deploy
    contract.publish_source(deployed_contract, silent=silent)
  File "C:\Users\Fedro\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py", line 392, in publish_source
    raise ValueError(f"API request failed with: {data['result']}")
ValueError: API request failed with: []`

this is what my deploy.py looks like


from scripts.helpful_scripts import get_account, get_contract
from brownie import DappToken, TokenFarm, network, config
from web3 import Web3

KEPT_BALANCE = Web3.toWei(100, "ether")

def deploy_token_farm_and_dapp_token():
    account = get_account()
    dapp_token = DappToken.deploy({"from": account})
    token_farm = TokenFarm.deploy(
        dapp_token.address,
        {"from": account},
        publish_source=config["networks"][network.show_active()]["verify"],
    )
    tx = dapp_token.transfer(
        token_farm.address, dapp_token.totalSupply() - KEPT_BALANCE, {"from": account}
    )
    tx.wait(1)
    weth_token = get_contract("weth_token")
    fau_token = get_contract("fau_token")
    dict_off_allowed_tokens = {
        dapp_token: get_contract("dai_usd_price_feed"),
        fau_token: get_contract("dai_usd_price_feed"),
        weth_token: get_contract("eth_usd_price_feed"),
    }
    add_allowed_tokens(token_farm, dict_off_allowed_tokens, account)
    return token_farm, dapp_token

def add_allowed_tokens(token_farm, dict_of_allowed_tokens, account):
    for token in dict_of_allowed_tokens:
        add_tx = token_farm.addAllowedTokens(token.address, {"from": account})
        add_tx.wait(1)
        set_tx = token_farm.setPriceFeedContract(
            token.address, dict_of_allowed_tokens[token], {"from": account}
        )
        set_tx.wait(1)
    return token_farm

def main():
    deploy_token_farm_and_dapp_token()`

I don't really understand what's going on here, also I've tried to find solutions online but none were useful

Could someone help me on this please?

cromewar commented 2 years ago

Hello @DieKant the code is complaining about the API key, if you have configured the parameter "verify=true" for kovan on your brownie-config.yaml you will also have to add the EtherScan API key to you .env otherwise it won't work.

DieKant commented 2 years ago

Hi @cromewar

I do have both an etherscan API key in my .env file as ETHERSCAN_TOKEN and the "verify=true" in my brownie-config.yaml under the kovan network

I've tried to solve this multiple times but I didn't find a solution yet

EDIT: closed issue by error, reopening it

cromewar commented 2 years ago

Hum strange as the error is complaining bout that verification, could you change the verify to false, and see if it pass through? just to confirm is a problem with the API key.

DieKant commented 2 years ago

Hi @cromewar

I solved the issue by putting True instead of config["networks"][network.show_active()]["verify"] in the publish_source option

This doesn't make any sense whatsoever, I made this custom test (it's right below this text) and it passes the assertion phase, I don't understand why if it's the same exact thing it gives an error when I use it one way instead of another

` used this command-> brownie test -k test_is_it_true --network kovan

def test_is_it_true():
    verify = config["networks"][network.show_active()]["verify"]
    assert verify == True

gives this output->
INFORMAZIONI: impossibile trovare file corrispondenti ai 
criteri di ricerca indicati.
Brownie v1.17.1 - Python development framework for Ethereum

================================================================================================== test session starts ==================================================================================================
platform win32 -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: D:\SolidityProjects\full-stack-defi
plugins: eth-brownie-1.17.1, hypothesis-6.24.0, forked-1.3.0, xdist-1.34.0, web3-5.24.0
collected 9 items / 8 deselected / 1 selected

tests\unit\test_token_farm_unit.py .                                                                                                                                                                               [100%]

============================================================================================ 1 passed, 8 deselected in 6.19s ============================================================================================ 
`
cromewar commented 2 years ago

You are awesome @DieKant I think this should be because the contract must be verified in order to be executed (don't know why tough).