Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Ingests a smart contract's ABI and autogenerates boilerplate code for making web3 calls.
An easy way to autogenerate boilerplate code for calling web3.js so your app can communicate with Ethereum.
Install globally via npm
, yarn
, or your preferred Javascript package manager:
npm install -g abi2lib
// OR
yarn global add abi2lib
If you are on Windows, you might need to refresh your path by restarting the terminal.
You can also install abi2lib
in your own project
npm install --save abi2lib
// OR
yarn global add abi2lib
Use in your terminal of choice by running:
abi2lib <contract_path> [options]
The options let you specify config values directly in the command, or specify a path to a config file. If you do not specify an output directory via an option, then it will be created in the working one. Run abi2lib --help
to learn more.
Use in your own nodejs scripts:
const abi2lib = require('abi2lib');
abi2lib.generate(contract_path, output_folder, config_options);
Either of these methods will generate a directory named <ContractName>ContractLib
which contains all of your autogenerated code. You can then use that code to communicate with your smart contract via:
const BaseController = require('<ContractName>ContractLib/<ContractName>Controller.js');
const ContractController = new BaseController();
// Async method, returns Promise; configures library with
// network ID of currently active network.
await ContractController.detectNetwork();
// Perform transaction using config values & required inputs
ContractController.post_<fxnA>(fromAddr, [value if allowed], ...contractInputs);
// Query output of contract using required inputs, does not perform transaction
ContractController.get_<fxnB>(fromAddr, ...contractInputs);
The optional config object includes constants for configuring web3 calls.
{
"eth": {
"provider": "http://localhost:8545",
"default_gas": 0,
"default_gasPrice": 40
}
}
The Controller class will have methods corresponding to each of the function descriptions listed in the ABI. If the function can be called with inputs, then there will be a method shaped like:
post_<fxnName>(from, [value if fxn is payable], [fxnParams...]){
// Properly configured call to contract's `send` function, triggers transaction
}
If the function also has outputs, then there will be a method shaped like:
get_<fxnName>(from, [inputParams...]){
// Properly configured call to contract's `call` function, triggers no transaction
}
Outputs a directory named <ContractName>ContractLib
which contains:
GenericEthConnector.js
: Generically converts ethereum read/write calls into web3 calls.<ContractName>Controller.js
: Contains all generated methods corresponding to the contract.contract.json
: A copy of your chosen smart contract ABI JSONconfig.json
: A copy of your chosen config JSONabi2lib
is developed & maintained by Eximchain, released for public use under the Apache-2.0 License.
Output from abi2lib
uses the same license.
FAQs
Ingests a smart contract's ABI and autogenerates boilerplate code for making web3 calls.
The npm package abi2lib receives a total of 2 weekly downloads. As such, abi2lib popularity was classified as not popular.
We found that abi2lib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.