ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.97k stars 1.69k forks source link

Pass string[] to function #1992

Closed Garito closed 3 years ago

Garito commented 3 years ago

Hi! Giving this signature: address, string[] calldata, string[] calldata

I'm trying to pass parameters as: w3.toChecksumAddress(address), ["val1", "val2"], ["val3", "val4"]

But it fails as detects: (<class 'str'>, <class 'list'>, <class 'list'>) instead of: (address,string[],string[])

Is this library updated to support string[]? or am I doing something wrong? How should I pass those params?

Thanks

wiseaidev commented 3 years ago

toChecksumAddress takes only one parameter, which is address, and builds a checksum based upon it as follows:

>>> w3.toChecksumAddress(0x999f348959e611f1e9eab2927c21e88e48e6ef45)
'0x999F348959E611F1E9eab2927c21E88E48e6Ef45'
Garito commented 3 years ago

As I'm using it? What's the point? Sorry for not understanding it :p

wiseaidev commented 3 years ago

I am not sure what your intention is in this issue. However, it seems like you are trying to make a new proposal or suggestion for the toChecksumAddress method. Therefore, it would be great to elaborate more on what you expect that function to do? And what do you mean by string[]? What is calldata used for? Answering these questions would make it easier for the project's maintainers to help you out with your issue. If you are coding with a statically typed language like c# and java, string[] is equivalent to list in python.

w3.toChecksumAddress(address), ["val1", "val2"], ["val3", "val4"]

Here you are not passing ["val1", "val2"] and ["val3", "val4"] as parameters to the toChecksumAddress method, instead you are building a tuple of three items of the following order:

(<class 'str'>, <class 'list'>, <class 'list'>)

Where the first item <class 'str'> is the return value of the toChecksumAddress function, and the other two <class 'list'> represents the previous two lists: ["val1", "val2"] and ["val3", "val4"] . That is why the REPL has shown these results.

Garito commented 3 years ago

Sorry, but you should check the parenthesis to notice that I've not change its signature What I'm asking is why a signature as address, string[], string[] fails with those parameters types in python w3.toChecksumAddress(address), ["val1", "val2"], ["val3", "val4"] (address, List[str], List[str]) that should become address, string[], string[]

Is this making more sense, now?

kclowes commented 3 years ago

@Garito That seems like it should work. Maybe the ABI is wrong? It's hard to tell without seeing the actual code. These docs might help, but if you're still having trouble please post a minimum reproducible example along with the actual error and we can help troubleshoot further!

Garito commented 3 years ago

I'm agree that should work But I should suspect that it is a problem with this library keeping up with solidity since: 1.- It should work since python List[str] should be exactly translated to string[] 2.- The docs you provide doesn't include any example with string[] (prove that, at least, the docs are outdated)

The abi, per se, shouldn't be a problem since I'm passing the one that generates the compiler as it is

kclowes commented 3 years ago

The docs should be up to date. Can you provide a code example of what you're trying to do and the error message you're getting?

Garito commented 3 years ago

I've deployed and used this contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract TestArrayOfStrings {
  event Log(string[] calldata strings);
  function passingArrayOfStrings(string[] calldata aBunchOfStrings) public {
    emit Log(aBunchOfStrings);
  }
}

with success (https://ropsten.etherscan.io/tx/0x7c79db9593bd510eebad1f9a0dd6b2f7f58dd2479f740531801b9a7bcb394daf) so my assumption about the List[str] to string[] conversion seems to be plain wrong

Since I can't publish the actual code, feel free to close this issue if you like

kclowes commented 3 years ago

Okay, sounds good. Feel free to open a new issue if you need more help!

Garito commented 3 years ago

thanks