### pip install:
$ sudo apt-get install python3-pip
$ sudo pip3 install virtualenv
#once
$ virtualenv -p python3 ~/.venv-py3
# each session:
$ source ~/.venv-py3/bin/activate
Current session is: (.venv-py3) user$
python file:
#!/usr/bin/env python
from __future__ import print_function
from web3 import Web3
#from web3.auto import w3
import json, sys, os
from web3.providers.rpc import HTTPProvider
os.chdir(sys.path[0]);
web3 = Web3(HTTPProvider('http://localhost:8545'))
fileAddr = open("address.json", "r")
contractAddress = fileAddr.read().replace("\n", "")
with open('abi.json', 'r') as abi_definition:
abi = json.load(abi_definition)
smartContract = web3.eth.contract(contractAddress, abi=abi); #<====Error occurs!!!!
When I use following line on my python file:
smartContract = web3.eth.contract(contractAddress, abi=abi);
I receive the following error:
Traceback (most recent call last):
File "getClusterAddresses.py", line 19, in <module>
eBlocBroker = web3.eth.contract(contractAddress, abi=abi);
File "/home/alper/.venv-py3/lib/python3.5/site-packages/web3/eth.py", line 350, in contract
return ContractFactory(address)
File "/home/alper/.venv-py3/lib/python3.5/site-packages/web3/contract.py", line 200, in __init__
self.address = normalize_address(self.web3.ens, address)
File "/home/alper/.venv-py3/lib/python3.5/site-packages/web3/utils/normalizers.py", line 160, in normalize_address
validate_address(address)
File "/home/alper/.venv-py3/lib/python3.5/site-packages/web3/utils/validation.py", line 116, in validate_address
raise InvalidAddress("Address has an invalid EIP checksum", value)
web3.exceptions.InvalidAddress: ('Address has an invalid EIP checksum', '0xfe80e4c67dc34539f2fe2ea88277635f9f809fc4')
If you鈥檙e pulling the address from a database I would suggest using web3.toChecksumAddress(dbAddress).
Honestly, I always use the toChecksum just Incase.
I am actually reading it from a file. For example abi.json contains the abi of the smart-contract and address.js contains its address. Should I do: dbAddress = web3.toChecksumAddress(dbAddress) ? @dangell7
Always.
Wow it worked, thanks!! Should I do it also for abi? @dangell7
No not for the abi. Just for any address that doesn鈥檛 come directly from web3 or metamask. Glad to help tho. If you want more. Here is my repo. Https://github.com/samyagency/samy
Most helpful comment
If you鈥檙e pulling the address from a database I would suggest using web3.toChecksumAddress(dbAddress).
Honestly, I always use the toChecksum just Incase.