web3.php icon indicating copy to clipboard operation
web3.php copied to clipboard

Not compatible with ABIEncoderV2 when receiving struct

Open AdamMiltonBarker opened this issue 5 years ago • 15 comments

Just to let you know you have a problem with ABIEncoderV2 if you are trying to call a function that returns a struct.

Call to a member function staticPartLength() on integer

AdamMiltonBarker avatar Sep 20 '20 02:09 AdamMiltonBarker

@AdamMiltonBarker hi, im getting this error too, how do you fix it?

lifenglibao avatar Jan 25 '21 08:01 lifenglibao

Hello. Any news on this ?

SelimTavukcuoglu avatar Apr 01 '21 14:04 SelimTavukcuoglu

I'm getting the same issue. Is there any update?

ZakZubair avatar Apr 20 '21 16:04 ZakZubair

I'm getting the same error. Is there a fix for this issue?

The error is on this line:/Contracts/Ethabi.php:226

bwu1 avatar Jul 17 '21 17:07 bwu1

any updates on this?

daryledesilva avatar Dec 18 '21 13:12 daryledesilva

So here, I've been looking through the code, trying to figure out how to fix this with a real case. This will require the addition of a new type tuple[]. This is obviously not supported at the moment.

This will break when you have an array of structs being returned. Let's say you have a GameItem[] as the return type. This will break because of two reasons. The first reason is that the tuple[] type doesn't exist. The second reason is that the tuple[] has a different output structure as the other types. There is a 'components' portion, per tuple that contains a set of elements (uint, int, ect...).

Stackout avatar Feb 26 '22 10:02 Stackout

Hello, trying to fix that as well, but I'm a little lost in what we need to change in the code to support the decoding for this tuple[] solidity type. Is this something complex to implement in the current library architecture or a good first issue as mentioned by the tag affected to this issue ;-)

I didn't find yet any solution/other lib in PHP to handle smartcontract which return array of structs (tuple[])

MariusMez avatar Mar 05 '22 08:03 MariusMez

@sc0Vu Hi, what's your plan about supporting ABIEncoderV2 tuple[] type ?

MariusMez avatar Mar 07 '22 08:03 MariusMez

Hello,

is there any update on this?

andreitode avatar Apr 15 '22 12:04 andreitode

If anyone still encounters, the solution I found was: take the txData returned by the call itself, strip leading 0x, split at each 64 chars (32 bytes) and based on the struct of the function, decode each param by it's own type.

struct structure in my case: { uint256 uint256 address }

so I splitted the string at each 64 chars, so I receive a total of 11 items, first item is 0x20, it means 32 bytes, the second item is the length of structs, in my case: 3 so I take the next 3 batches of each 3 items and decode following: uint256 decode for split[2] uint256 decode for split[3] address decode for split[4] and so on till split[10]

Hope it helps someone, been wrapping my head for few hours

andreitode avatar Apr 15 '22 13:04 andreitode

If anyone still encounters, the solution I found was: take the txData returned by the call itself, strip leading 0x, split at each 64 chars (32 bytes) and based on the struct of the function, decode each param by it's own type.

struct structure in my case: { uint256 uint256 address }

so I splitted the string at each 64 chars, so I receive a total of 11 items, first item is 0x20, it means 32 bytes, the second item is the length of structs, in my case: 3 so I take the next 3 batches of each 3 items and decode following: uint256 decode for split[2] uint256 decode for split[3] address decode for split[4] and so on till split[10]

Hope it helps someone, been wrapping my head for few hours

That's basically parsing the ABI code manually ;)

I've been waiting for this too for some months already... I'm starting a custom library now on top of some libraries from web3p & kornrunner.

drlecks avatar May 19 '22 09:05 drlecks

Hey, created new pull based on Abaowu pull with minimal code... any chances to include it? https://github.com/web3p/web3.php/pull/299

If anyone wants to test: https://github.com/slawomir-pryczek/web3.php

slawomir-pryczek avatar Oct 16 '22 07:10 slawomir-pryczek

It would be nice if this feature could be somehow prioritized, as it is also mentioned in #265.

If that's not the case, it should be clearly communicated that the library will not be maintained anymore. In that case, the community could potentially focus on alternatives (e.g. @drlecks's simple-web3-php)

vterzic avatar Dec 12 '22 10:12 vterzic

Hey, just FYI, new ABI format is more complex than that so even using these patches (mine or Abaowu) won't make it fully AbiV2 compatible. And looking at abi encoder/decoder code probably it'll need rewrite...

slawomir-pryczek avatar Dec 12 '22 17:12 slawomir-pryczek

Hey guys any update on Tuple issue? Help needed :)

paulgotea avatar Feb 06 '23 23:02 paulgotea