Giter Club home page Giter Club logo

evm-tx-input-decoder's Introduction

EVM Transactions Input Decoder

This is a simple gem that helps decoding and encoding transactions input data for EVM based blockchains like Ethereum and Tron.

Installation

Run

gem install evm-tx-input-decoder

or add

gem 'evm-tx-input-decoder', require: 'evm_tx_input'

to your Gemfile.

Usage

Decoding

Let's consider decoding process by example USDT transaction in an Ethereum blockchain.

The input data is 0xa9059cbb00000000000000000000000003cb76e200ba785f6008c12933aa3640536d2011000000000000000000000000000000000000000000000000000000a083712e00, which can be found in More details section.

The USDT token ABI can be found by this url

require 'open-uri'
require 'evm_tx_input'

json = URI.open('http://api.etherscan.io/api?module=contract&action=getabi&address=0xdac17f958d2ee523a2206206994597c13d831ec7&format=raw') { |file| file.read }
abi = JSON.parse(json)
input = '0xa9059cbb00000000000000000000000003cb76e200ba785f6008c12933aa3640536d2011000000000000000000000000000000000000000000000000000000a083712e00'

function = EvmTxInput::Decoder.new(abi).decode_input(input)
function.id #=> "a9059cbb"
function.name #=> "transfer"
function.arguments
# [#<EvmTxInput::Argument:0x00000001107ffa60 @name="_to", @type="address", @value="0x03cb76e200ba785f6008c12933aa3640536d2011">,
#  #<EvmTxInput::Argument:0x00000001107ffa10 @name="_value", @type="uint256", @value=689400000000>]

Encoding

Following decoding procedure let's encode the previous result.

require 'evm_tx_input'

function_name = 'transfer'
types = %w[address uint256]
args = ['0x03cb76e200ba785f6008c12933aa3640536d2011', 689400000000]
EvmTxInput::Encoder.encode_input(function_name, types, args)
#=> "0xa9059cbb00000000000000000000000003cb76e200ba785f6008c12933aa3640536d2011000000000000000000000000000000000000000000000000000000a083712e00"

For more details read the documentation.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rkotov93/evm-tx-input-decoder.

License

The gem is available as open source under the terms of the MIT License.

evm-tx-input-decoder's People

Contributors

rkotov93 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

all0x0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.