from ethpm_cli.config import setup_w3
# `setup_w3(chain_id, private_key)` is a helper method from ethpm-cli
# that automatically connects to the designated chain via Infura and
# authenticates your account to automatically sign all transactions
w3 = setup_w3(1, 'PRIVATE_KEY')
# Temporary security measure until PM api stabilizes
w3.enable_unstable_package_management_api()
# Grab the dai package from the snakecharmers erc20 registry
w3.pm.set_registry('erc20.snakecharmers.eth')
dai_pkg = w3.pm.get_package('dai-dai', '1.0.0')
dai = dai_pkg.deployments.get_instance('DSToken')
# Verify that everything's working
dai.functions.name().call()
> b'Dai Stablecoin v1.0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
# Grab the compound package from the snakecharmers defi registry
w3.pm.set_registry('defi.snakecharmers.eth')
compound_pkg = w3.pm.get_package('compound', '1.0.0')
cDai = compound_pkg.deployments.get_instance('cDAI')
# Verify that everything's working
cDai.functions.name().call()