0

Hello I 'am trying to generate Go ethereum binding for a smart contract in which I have a function that takes a struct as argument. It seems that abigen doesn'tsupport this argument.

struct Device
{
    bytes16 UUID;
    bytes16 hardware_UUID;
    string phone_Number;
}

function SaveDevice(Device memory device) public returns (bool)

{
    Device_Table[device.UUID]=device;
    Device_HardTable[device.hardware_UUID]=device;
}

Is there any ssolution for this problem?

3
  • A public function cannot take a struct as input. Pass the struct fields instead. Jul 3, 2019 at 9:22
  • Can it return a struct?
    – MS B
    Jul 3, 2019 at 9:31
  • No....................... Jul 3, 2019 at 9:40

1 Answer 1

0

You cannot pass struct as function parameter and function cannot return struct, but you can pass struct parameters as function parameters and function can return struct parameters. The following code might help you:

pragma solidity 0.5.0;

contract DeviceContract {
    struct Device {
        bytes16 hardware_UUID;
        string phone_Number;
    }

    mapping (bytes16 => Device) list_with_devices; 

    function saveDevice(bytes16 _UUID, bytes16 _hardware_UUID, string memory _phone_Number) public returns (bool)  {
        list_with_devices[_UUID] = Device(_hardware_UUID, _phone_Number);
    }

    function getDevice(bytes16 _UUID) public view returns(bytes16, string memory) {
        return (list_with_devices[_UUID].hardware_UUID, list_with_devices[_UUID].phone_Number);
    }
}
1
  • can we return a table instead of struct?
    – MS B
    Jul 3, 2019 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.