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

Call methods with struct parameters (ABIEncoderV2) #5434

Closed
Amxx opened this issue Oct 5, 2018 · 1 comment
Closed

Call methods with struct parameters (ABIEncoderV2) #5434

Amxx opened this issue Oct 5, 2018 · 1 comment

Comments

@Amxx
Copy link

Amxx commented Oct 5, 2018

What problem are you trying to solve?
I am trying to call a smart contract's method which arguments are/contain structs.

Contract is loaded and called using:

$.getJSON("contracts/test.json", json => {
    testInstance = web3.eth.contract(json.abi).at("0xBf...");
    testInstance.myMethod(JSON.stringify({ a: 17, b: 42, c: 0x0, d: "toto" }), { gas: 42000 });
});

Here is the relevant part of the ABI (description of myMethod)

{
	"constant": true,
	"inputs": [
		{
			"components": [
				{ "name": "a", "type": "uint256" },
				{ "name": "b", "type": "uint256" },
				{ "name": "c", "type": "bytes32" }
				{ "name": "d", "type": "string"  }
			],
			"name": "myStruct",
			"type": "tuple"
		}
	],
	"name": "myMethod",
	"outputs": [
		{ "name": "", "type": "bool" }
	],
	"payable": false,
	"stateMutability": "view",
	"type": "function"
}

The cosole gives me Uncaught Error: invalid solidity type!: tuple. I tryed with and without JSON.stringify.
Ideally I would need access something like web3.eth.abi.encodeParameters, but I don't see such a element in the web3 object provided by metamask.

Note: web3js support this feature since version 1.0.0-beta.36, when it pulled the abiEncoder from ethers.js.

Any plan to support structures in calls anytime soon?

Additional Infos
I am using metamask 4.12.0 on chrome

@Amxx Amxx changed the title Call methods with struct parameters (ABIEncoderV2 Call methods with struct parameters (ABIEncoderV2) Oct 5, 2018
@danfinlay
Copy link
Contributor

We do not currently support web3 1.0 since it depends on subscriptions & websockets. If their feature was added by including ethers.js, you could probably encode these parameters using the ethers.js library.

Closing as a duplicate of #3642.

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