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

Decode transaction input #274

Open
wafcio opened this issue May 31, 2024 · 4 comments
Open

Decode transaction input #274

wafcio opened this issue May 31, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@wafcio
Copy link
Contributor

wafcio commented May 31, 2024

JSON RPC getTransactionByHash returns transaction details with "input" data. I have tried to find an easy way to decode the input field, but I haven't been able to find one.

The problem is that the first 32 bytes point to the function name, and the rest are related to decoding based on ABI. I need help finding a way to select a proper function from ABI.

@wafcio
Copy link
Contributor Author

wafcio commented Jun 5, 2024

I have found solution, it would be great to have it implemented in gem

# abi - JSON abi
# tx_input - Transaction input data

abi = abi.select { |a| a["name"].present? }

function_signatures =
  abi.each_with_object({}) do |a, hsh|
    hsh[Eth::Abi::Event.compute_topic(a)[0, 10]] = a
  end

types = function_signatures[tx_input[0, 10]]["inputs"].map { |input| input["type"] }

Eth::Abi.decode(types, tx_input[10..-1])

@q9f q9f added the enhancement New feature or request label Jun 23, 2024
@q9f
Copy link
Owner

q9f commented Jun 23, 2024

Sounds good to me. Do you mind supplying a test case or data?

Feel free to suggest a PR!

@wafcio
Copy link
Contributor Author

wafcio commented Jun 23, 2024

@q9f I don't know enough about eth.rb codebase. Moreover, it will be good to add parsing transaction log data

@q9f
Copy link
Owner

q9f commented Dec 17, 2024

Sorry, I mean, could you give me a snippet of code or a script that fails for you with which expectations so that I can investigate? I didn't mean you should implement tests.

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

No branches or pull requests

2 participants