Addresses

eth_sendTransaction 方法不存在/不可用 - web3.py

  • November 20, 2019

我正在嘗試向合約發送數據,但出現以下錯誤: 方法 eth_sendTransaction 不存在/不可用

這是程式碼:

from web3 import Web3

web3 = Web3(Web3.HTTPProvider("https://rinkeby.infura.io/v3/9fe6f0a016494dfeb4cecd7d1c98431a"))

from web3.middleware import geth_poa_middleware

web3.middleware_onion.inject(geth_poa_middleware, layer=0)

print(web3.eth.blockNumber)

x = web3.isAddress('0xacb0ceacb13e786644f0ab21aa044032ae925874')
print(x)

abi = '''
  ...
     '''

address = Web3.toChecksumAddress('0xacb0ceacb13e786644f0ab21aa044032ae925874')

lucas = '0x690809206b73994282910F1740a729a89aF4beCa'

myContract = web3.eth.contract(address=address, abi=abi)
key = myContract.functions.storeData([1,4]).transact({'from' : lucas})

print(key)

addedData = myContract.functions.getData(key).call()
print(addedData)

上面的程式碼可以正常連接到網路rinkeby,但是不能進行交易。storeData方法接受一個數組並返回一個 uint,它是並且在 Remix 中正常工作。

我正在使用元遮罩。

key = myContract.functions.storeData([1,4]).buildTransaction({'nonce': web3.eth.getTransactionCount(address)})

signed_tx = web3.eth.account.signTransaction(key, private_key='...')

web3.eth.sendRawTransaction(signed_tx.rawTransaction)

引用自:https://ethereum.stackexchange.com/questions/77637