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

[FEAT] Add encodeFunctionData function #3294

Open
ababyprogrammer opened this issue Mar 19, 2024 · 1 comment
Open

[FEAT] Add encodeFunctionData function #3294

ababyprogrammer opened this issue Mar 19, 2024 · 1 comment
Assignees

Comments

@ababyprogrammer
Copy link

ababyprogrammer commented Mar 19, 2024

ethers.js has a function called encodeFunctionData and it encodes a function and it's arguments into bytes. This is helpful especially when working with proxies and low level delegate calls.

Here is an example.

I'd think the API would look something like:

from web3 import Web3

Web3.encode_function_data("functionName(uint256 parameter1, uint256 parameter2...)", parameter1, parameter2...)

The function could look something like:

def encode_function_data(function_string: string, *parameters):
        return Web3.toHex(Web3.toHex(functionFragment)[0:4] + Web3.toHex([*parameters])

(I think).

@kclowes
Copy link
Collaborator

kclowes commented Mar 20, 2024

Does contract.encodeABI work for your use case or would you rather have it on the Web3 class?

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

No branches or pull requests

4 participants