Hi, I want to send a Hash (from INFURA IPFS) to a smart contract but I am having issues signing the transaction.
Background: I don’t want to run an Ethereum client on my RPi, so I am using the HTTPProvider from Web3. I used Truffle and Ganache to compile, migrate and interact with my smart contract. But switching from Ganache to HTTPProvider (compiled/migrate again with changes in truffle-config.js for HTTPProvider) generates some errors regarding web3.eth.deafult_account.
import json from web3 import Web3 blockchain_address = 'https://ropsten.infura.io/v3/..........................' w3 = Web3(Web3.HTTPProvider(blockchain_address)) # The filehash from IPFS filehash = 'randrom Hash' # Default account, worked at least in Ganache w3.eth.default_account = w3.eth.accounts[0] # Smart Contract Path and ABI contract_path = 'build/contracts/IPFS.json' contract_address = 'address' # Address from truffle migration using HTTPProvider with open(contract_path) as file: contract_json = json.load(file) contract_abi = contract_json['abi'] contract = w3.eth.contract(address=contract_address, abi=contract_abi) result = contract.functions.sendHash(filehash).transact() print(result.hex())
Error cases:
with w3.eth.default_account = w3.eth.accounts[0]
IndexError: list index out of range
with w3.eth.default_account = w3.eth.accounts[‘Metamask_account_address’]
TypeError: list indices must be integers or slices, not str
I tried using:
transaction = {
‘from’: ‘Metamask_Account_Address’,
‘to’: ‘SC_Address’,
‘chainId’: 3
}
in
result = contract.functions.sendHash(filehash).transact(transaction)
nothing worked. Did I miss some fundamental understanding what INFURA is?