patractlabs / py-patract

Substrate Contract SDK for Python As a part of Himalia
Apache License 2.0
11 stars 0 forks source link

Error when using ERC20 wrapper: No module named 'patractinterface.contracts' #7

Open stiiifff opened 3 years ago

stiiifff commented 3 years ago

When trying to use the ERC20 wrapper, and using an ERC20 contract already on-chain (deployed using Redspot), I am getting the following error:

ModuleNotFoundError: No module named 'patractinterface.contracts'

To test this, I am using a local Europa instance, and I have previously created, compiled and deployed an ERC20 contract using Redspot, and copied the erc20.json & erc20.wasm files to a res subfolder (as expected by the tutorial code).

Below is the test code:

    substrate=SubstrateInterface(url='ws://127.0.0.1:9944', type_registry_preset="default", type_registry={'types': {'LookupSource': 'MultiAddress'}})

    alice = Keypair.create_from_uri('//Alice')
    bob = Keypair.create_from_uri('//Bob')

    erc20 = ERC20.create_from_address(
        "128vhr5RJeWBnkh36NaMKAE7PP57hkFAYVBGzTAhecvWsnYw",
        os.path.join(os.path.dirname(__file__), 'res', 'erc20.json'),
        substrate
    )

    # read total supply
    total_supply = erc20.totalSupply()
    print("Total supply: {}", total_supply)

    transfer
    erc20.transfer_from(alice,
        from_acc=alice.ss58_address, 
        to_acc=bob.ss58_address, 
        amt=10000)

    erc20.transfer(alice, bob.ss58_address, 10000)

    # get balance
    alice_balance = erc20.balance_of(alice.ss58_address)

    # approve
    erc20.approve(alice, spender=bob.ss58_address, amt=10000)

    # get allowance
    alice_allowance = erc20.allowance(alice.ss58_address, bob.ss58_address)
polkadev commented 3 years ago

This package have upgrade to v0.3.1, and it contain some examples in https://github.com/patractlabs/py-patract/tree/master/examples/erc20, you can use it for example to test

polkadev commented 3 years ago

5 #6