0

I am working with the tutorial by freecodecamp.org and have the following error: ImportError: cannot import name 'LinkToken' from 'brownie It is also not able to import VRFCoordinatorMock which I am using at my helpful_script:

from web3 import Web3
from brownie import accounts, network, config, Contract, LinkToken, VRFCoordinatorMock
#...
contract_to_mock = {"link_token": LinkToken, "vrf_coordinator": VRFCoordinatorMock}
#...
def deploy_mocks():
    """
    Use this script if you want to deploy mocks to a testnet
    """
    print(f"The active network is {network.show_active()}")
    print("Deploying mocks...")
    account = get_account()
    print("Deploying Mock LinkToken...")
    link_token = LinkToken.deploy({"from": account})
    print(f"Link Token deployed to {link_token.address}")
    print("Deploying Mock VRF Coordinator...")
    vrf_coordinator = VRFCoordinatorMock.deploy(link_token.address, {"from": account})
    print(f"VRFCoordinator deployed to {vrf_coordinator.address}")
    print("All done!")
# ...

David from freecodecamp.org already created this browie-config.yaml file which exludes reports about the contracts:

dependencies:
  - OpenZeppelin/[email protected]
  - smartcontractkit/[email protected]
reports:
  exclude_contracts:
    - LinkToken
    - VRFCoordinatorMock
    - ERC721
    - EnumerableMap
    - Address
    - EnumerableSet
compiler:
  solc:
    remappings:
      - "@openzeppelin=OpenZeppelin/[email protected]"
      - "@chainlink=smartcontractkit/[email protected]"
dotenv: .env
wallets:
  from_key: ${PRIVATE_KEY}
networks:
  development:
    keyhash: "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311"
    fee: 100000000000000000
  goerli:
    vrf_coordinator: "0x2bce784e69d2Ff36c71edcB9F88358dB0DfB55b4"
    link_token: "0x326C977E6efc84E512bB9C30f76E30c160eD06FB"
    keyhash: "0x0476f9a745b61ea5c0ab224d3a6e4c99f0b02fce4da01143a4f70aa80ae76e8a"
    fee: 100000000000000000 # 0.1

The error occures when I am running the following deploy_and_create file:

from scripts.helpful_scripts import get_account, OPENSEA_URL, get_contract
from brownie import AdvancedCollectible, network, config

sample_token_uri = "https://ipfs.io/ipfs/Qmd9MCGtdVz2miNumBHDbvj8bigSgTwnr4SbyH6DNnpWdt?filename=0-PUG.json"


def deploy_and_create():
    account = get_account()
    # We want to be able to use the deployed contracts if we are on a testnet
    # Otherwise, we want to deploy some mocks and use those
    # Goerli
    advanced_collectible = AdvancedCollectible.deploy(
        get_contract("vrf_coordinator"),
        get_contract("link_token"),
        config["networks"][network.show_active()]["keyhash"],
        config["networks"][network.show_active()]["fee"],
        {"from": account},
    )

def main():
    deploy_and_create()

You can find the youTube Video under https://www.youtube.com/watch?v=M576WGiDBdQ&list=PLFLVQ12OWlUJ0EvLOdcJs-bNY5rqW_rXq&index=5&t=38144s and the github repository: https://github.com/PatrickAlphaC/nft-demo

Hope someone can help me, thanks in advance!

2 Answers 2

0

From what I can see, based on the logic of the code you posted here. It seems your issue is caused because you are not calling the deploy_mocks function from helpful_script.

Instead of:

def main():
    deploy_and_create()

You would need the following:

def main():
    deploy_mocks()
    deploy_and_create()

In short, your deploy_and_create file should function like this:

from scripts.helpful_scripts import get_account, OPENSEA_URL, get_contract, deploy_mocks
    from brownie import AdvancedCollectible, network, config
    
    sample_token_uri = "https://ipfs.io/ipfs/Qmd9MCGtdVz2miNumBHDbvj8bigSgTwnr4SbyH6DNnpWdt?filename=0-PUG.json"
    
    
    def deploy_and_create():
        account = get_account()
        # We want to be able to use the deployed contracts if we are on a testnet
        # Otherwise, we want to deploy some mocks and use those
        # Goerli
        advanced_collectible = AdvancedCollectible.deploy(
            get_contract("vrf_coordinator"),
            get_contract("link_token"),
            config["networks"][network.show_active()]["keyhash"],
            config["networks"][network.show_active()]["fee"],
            {"from": account},
        )
    
    def main():
        deploy_mocks()
        deploy_and_create()

Try this, and we will see how it goes.

4
  • No, unfortunately this is not the problem but thanks Oct 10, 2022 at 14:10
  • You get the same error?
    – Sky
    Oct 10, 2022 at 19:56
  • Yes, I cloned the finished repository and it worked fine but wasn't able to find the reason for mine not to work... Oct 11, 2022 at 3:37
  • Did you do: brownie compile before you tried to run the script?
    – Sky
    Oct 11, 2022 at 6:34
0

At the top of your script, you have

from brownie import ... LinkToken

Which means you are importing the LinkToken from your contracts folder.

You'll need to add the LinkToken contract to your contracts folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.