2

I have written a smart contract function using solidity consisting of different parameters given below

function addDevice(address _address, string _deviceType, string _deviceName, string _minerID, string _deviceID) public
{
    DeviceData storage device = devices[_address];

    device.deviceType = _deviceType;
    device.deviceName = _deviceName;
    device.minerID = _minerID;
    device.deviceID = _deviceID;

    devicesAddresses.push(_address) -1;
}

I am using web3.py to call this function with the given commands as

D_Address = input("Device Address ").encode()
D_Type = input("Device Type ")
D_Name = input("Device Name ")
M_ID = input("Miner ID ")
D_ID = input("Device ID ")


tx_hash = contract_instance.functions.addDevice(D_Address,D_Type,D_Name,M_ID,D_ID).transact()
tx_receipt = web3.eth.waitForTransactionReceipt(tx_hash)

In REMIX, this smart contract is working fine, but when I run the file, it shows the following error

Found 1 function(s) with the name addDevice: ['addDevice(address,string,string,string,string)'] Function invocation failed due to no matching argument types.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Khizar Hameed
  • 41
  • 1
  • 7

1 Answers1

1

Delete .encode(), because you should pass in a string for the address field.

Let me know if it still doesn't work!

StillFantasy
  • 1,677
  • 9
  • 21
  • After deleting the .encode, its shows the following error '''web3.exceptions.InvalidAddress: ('Web3.py only accepts checksum addresses. The software that gave you this non-checksum address should be considered unsafe, please file it as a bug on their platform. Try using an ENS name instead. Or, if you must accept lower safety, use Web3.toChecksumAddress(lower_case_address).', '0x5fa806f48a26b45904b77b2f5382ef7a1e834699')''' – Khizar Hameed Nov 30 '19 at 03:36
  • 1
    Yeah, just transform it into the checksum address, after that, I think it should work! @KhizarHameed – StillFantasy Nov 30 '19 at 04:46