New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

evm-tx-input-decoder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

evm-tx-input-decoder

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 03 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc