Isues with eth_contract macro

Hello. I am having issues with the eth_contract macro.

Consider a situation in which I have an Ethereum contract called TwoGather.sol, and discovery compile successfully compiles it into the build folder as build/smart_contracts/TwoGather.json

First question: It seems that I cannot just pass this file to the eth_contract macro, but that I first need to extract only the array that can be found at the abi property, is that correct? I was getting errors passing the file from the build/smart_contracts folder and that seemed to get me further.

I think a good developer flow would allow the entire built build/smart_contracts/TwoGather.json file to be passed. Thank you for clarifying this issue/question.

Second, after creating a second json file that contains only the array that could be found at the abi property from the TwoGather.json file called TwoGather_abi_only.json, I am now getting this parsing error, with no further clarification on the issue.

97 | #[eth_contract("TwoGather_abi_only.json")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: called `Result::unwrap()` on an `Err` value: TokenParseError { error: "unexpected token" }

And here is the contents of TwoGather_abi_only.json:

[
    {
      "inputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "proposal_id",
          "type": "bytes[48]"
        }
      ],
      "name": "activateProposal",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    }
]

Can you advise on this parsing error and how to resolve it?

Also, from a developer process point of view, it would of course be best and least error prone if we can just pass the full contents of build/smart_contracts/TwoGarther.json to the eth_contract macro.

Thank you for also addressing these issues.

Hi Brendan, based on the voting demo and contract_with_eth_calls that should work, you’re on the right track with the abi.
Could you perhaps push a project to github demonstrating the error?

Interesting suggestion to refer to the build output and maybe it’s possible/feasible, would still have to support abi like this as not all contracts will be part of the project. You could copy the abi from a deployed contract using etherscan for example.

@taariq Thx. I will try a few things to see if I can find the problem. But I would still request these improvements to discovery:

  • Allow a way to pull the abi from a locally built contract json. This will facilitate development of custom contracts more easily.
  • Provide better error messages when an abi fails to parse - at least the line/character number where the failure occurred!

Thx.

@taariq By process of elimination I found the issue in the ABI, and I think there is a bug in discovery.

When I changed

"inputs": [
        {
          "name": "proposal_id",
          "type": "bytes[48]"
        }
      ],

to

"inputs": [
        {
          "name": "proposal_id",
          "type": "bytes"
        }
      ],

by removing the length [48] from the bytes then the error went away.

I think this must be an error in your discovery parser, because the solidity contract compiled fine and the bytes[48] is a valid type in solidity.

I would encourage your team to look into/fix that bug. Thx.

Hi Brendan,
I’ve reproduce the error by using your json, but can you also include the solidity contract or snippet of the function please?

1 Like

@taariq Hi, Taariq. My smart contract is a simple placeholder at this point: I have been focusing on the secret contract first and was then going to turn to the smart contract. Here it is:

pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;

contract TwoGather {

     constructor() public {
    }

    function activateProposal(bytes[48] memory proposal_id) public {

    }

}

Thanks Brendan, yes this should work and I’ve created a test project to attach to an open issue in discovery-cli

Will update when it’s resolved.

1 Like