Socket
Book a DemoInstallSign in
Socket

abigen-extended

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abigen-extended

Based on the contract ABI, **abigen** create some Go code to interact with our smart contract functions in a pleasant way (automatic type binding, parsing logs, etc…).

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

ABIGEN Extended

Based on the contract ABI, abigen create some Go code to interact with our smart contract functions in a pleasant way (automatic type binding, parsing logs, etc…).

But this is not enough to having a full control on our Smart Contract, indeed some features are missing:

  • Make Static Call on non-view functions
  • Get the hash of events
  • Getting the contract address on an instance
  • Getting the ABI of an instance
  • Extract Parsed event from logs receipt

That's why we have created this tool. Basically it use abigen under the hood and add some code at the bottom on the file.

Installation

Install abigen: https://geth.ethereum.org/docs/install-and-build/installing-geth

# Install the package
npm install -g abigen-extended
# Or with yarn
yarn global add abigen-extended

Usage

Generate Go Binding

abigen-extended --abi <PATH_TO_ABI_FILE> --out <PATH_TO_GO_FILE> --pkg <GO_PACKAGE_NAME>

For the rest of the readme, I suppose we use the following command for importing WETH contract:

abigen-extended --abi weth.abi.json --out weth.go --pkg weth

Access new fields on contract instance

wethContract, err := weth.NewWeth(address, client)

wethContract.Address // Get the instance address
wethContract.Backend // Get the client instance
wethContract.ABI     // Get the parsed ABI

Access hash of events

weth.EVENT_APPROVAL_HASH // Hash of approval event
weth.EVENT_TRANSFER_HASH // Hash of transfer event
// ...

Parse event from receipt

events, err := wethContract.ParseReceiptTransfer(receipt) // Get all parsed transfer logs from the receipt

Static call for non view function

// Perform static call on transfer (non payable)
transferSuccess, err := wethContract.StaticTransfer(&bind.CallOpts{ From: address }, receiver, amount)

// Perform static call on deposit (payable)
err := wethContract.StaticDeposit(&bind.CallOpts{ From: address }, payableETHValue)

FAQs

Package last updated on 07 Jan 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