web3s.py
from web3 import Web3
import json
url = 'https://kovan.infura.io/v3/NODE'
web3 = Web3(Web3.HTTPProvider(url))
abi = json.loads('[{"ABI"}]')
Raw_ADDRESS = MY_ADDRESS
address = web3.toChecksumAddress(Raw_ADDRESS)
contract = web3.eth.contract(address=address,abi=ABI)
default_GasPrice = '5'
def firstMethod(Address1,publicKey,privateKey,GasPrice = default_GasPrice ) :
Address1 = web3.toChecksumAddress(Address1)
publicKey = web3.toChecksumAddress(publicKey)
if web3.isConnected() :
nonce = web3.eth.get_transaction_count(publicKey)
transaction = contract.functions.firstMethod(Address1).buildTransaction({
'from': publicKey ,
'gasPrice': web3.toWei(GasPrice, 'gwei'),
'nonce': nonce ,
})
...
当我在 web3s.py 中定义 address1 和 address2 时,代码运行良好,但是当我在导入后在另一个文件(来自 Django-Rest View)中调用 firstMethod() 并传递相同的参数时,它返回:
File "venv/lib/python3.8/site-packages/eth_utils/conversions.py", line 159, in hexstr_if_str
raise ValueError(
ValueError: when sending a str, it must be a hex string. Got: "'0x6e...32'"
如图所示,我使用 infura 而不是 etherscan
问题出在哪里 ?