Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web3 can't work with abitype Tuple #260

Open
devedse opened this issue Apr 17, 2022 · 5 comments
Open

web3 can't work with abitype Tuple #260

devedse opened this issue Apr 17, 2022 · 5 comments

Comments

@devedse
Copy link
Contributor

devedse commented Apr 17, 2022

I'm currently working on a SmartContract that has the following method:

struct Color {
    uint8 R;
    uint8 G;
    uint8 B;
}

function create(uint index, Color calldata backgroundColor, Color calldata textColor, uint number) {
    ....
}

I tried calling this function however web3 shows the following error:

> web3 contract call --address xxxxxx --abi Test.abi --function create 1 "[100, 12, 200]" "[50, 100, 10]" 1
ERROR: Error calling contract: unsupported input type (uint8,uint8,uint8)
@treeder
Copy link
Contributor

treeder commented Apr 17, 2022

I haven't used structs, but maybe try setting the experimental flag and passing in the struct name with the parameters like here: https://ethereum.stackexchange.com/questions/65980/passing-struct-as-an-argument-in-call

@devedse
Copy link
Contributor Author

devedse commented Apr 18, 2022

Could you maybe provide an example of what you mean? I had already included the pragma abiencoderv2 in my smart contact

@treeder
Copy link
Contributor

treeder commented Apr 18, 2022

I was thinking something like it has in that stackoverflow: "SetStruct((int256,int256))" instead of an array like you're using "[100, 12, 200]". I have no idea if that will work, but worth a test.

@devedse
Copy link
Contributor Author

devedse commented Apr 18, 2022

Ok I'm still not sure what you mean exactly. Here's what I have now:

pragma solidity >=0.4.22 <0.9.0;

contract Test {

    struct Color {
        uint8 R;
        uint8 G;
        uint8 B;
    }

    function create(uint lockIndex, Color calldata backgroundColor) public {

    }
}

With abi:

[
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "lockIndex",
				"type": "uint256"
			},
			{
				"components": [
					{
						"internalType": "uint8",
						"name": "R",
						"type": "uint8"
					},
					{
						"internalType": "uint8",
						"name": "G",
						"type": "uint8"
					},
					{
						"internalType": "uint8",
						"name": "B",
						"type": "uint8"
					}
				],
				"internalType": "struct Test.Color",
				"name": "backgroundColor",
				"type": "tuple"
			}
		],
		"name": "create",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	}
]

I deployed this to here:
https://ropsten.etherscan.io/address/0x45cd215365cdf384ea65a65927501e6a40571266#code

And I'm calling this by doing:

web3 contract call --address 0xa9637b51e5b413e4C9D35E2663eB748396Df79a9 --abi Test.abi --function create 3 "SetStruct((int256,int256,int256))"

Which results in the following error:

ERROR: Error calling contract: unsupported input type (uint8,uint8,uint8)

From Etherscan I can do the following which works:
image
Working transaction: https://ropsten.etherscan.io/tx/0x900c1805dac74134dba0284b96656131eeeb13a97b08ff1ddb69d182e8ac9d48

@devedse
Copy link
Contributor Author

devedse commented Apr 24, 2022

I have since written my own Web3Cli to basically be able to pass structs to a constructor of a smart contract or a function.
So if anyone is looking for this feel free to check out my tool:
https://github.com/devedse/DeveWeb3Cli

For this library it could be useful as a first idea too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants