So I want to interact with my Smart Contract from remix with python library called Web3. The problem is when I try to call the function from the smart contract it runs successfully but it only returns an empty array instead of the actual data.

Solidity Code:

pragma solidity 0.5.1;

contract MyContract {
    Evidence[] public evidence;

    struct Evidence {
        string name;
        string location;
    function addPerson(string memory name, string memory location) public {
        evidence.push(Evidence(name, location));

Python Code:

import json
from web3 import Web3

url = 'HTTP://'
web3 = Web3(Web3.HTTPProvider(url))

web3.eth.defaultAccount = web3.eth.accounts[0]

abi = json.loads('my json')
bytecode = "my bytecode"

status = web3.isConnected()

if status == True:
    MyContract = web3.eth.contract(abi = abi, bytecode = bytecode)
    transaction = MyContract.constructor().transact()
    receipt = web3.eth.waitForTransactionReceipt(transaction)
    contract = web3.eth.contract(
        address = receipt.contractAddress,
        abi = abi
    tx_hash = contract.functions.addPerson("Adam", "Near House").call()

    print("Not Connected")
  • 1
    Can you show me the code where you're trying to get the evidence field? – Ivan Andrusenko Mar 29 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.