@riaskov/iohtee-abi-wrapper
v2.0.9
Published
Generate TypeScript wrapper class for Solidity smart contract ABI
Downloads
12
Maintainers
Readme
IohTee ABI Wrapper
IohTee ABI Wrapper is a TypeScript wrapper for EVM-compatible ABI of Solidity smartcontract. It takes raw json artifact file and render ready-to-use TS-wrapper. Use viem v2 internally.
Install
$ npm install @riaskov/iohtee-abi-wrapper --global --no-save
Use
$ iohtee-abi-wrapper -o ./generated ./abi/*
Now you can import generated contract's wrapper from ./generated
folder like
import {
CtorParams,
XXXContract,
} from './generated/XXXContract'
Recipes
- Generate just regular TS wrappers for ABI files located in
./abi/*
and put them into./generated
$ iohtee-abi-wrapper -o ./generated ./abi/*
- Generate just regular TS wrappers for ABI files located in
./abi/*
AND minified js version of wrapper and put them into./generated
$ iohtee-abi-wrapper -m -o ./generated ./abi/*
- Generate just regular TS wrappers for ABI files located in
./abi/*
AND minified js version of wrapper and put them into./generated
AND create a nice HTML-docs for wrapper
$ iohtee-abi-wrapper -m -d ./docs -o ./generated ./abi/*
ATTENTION! All files in specified docs
dir will be removed each time the command will be invoked!
Generated TS-wrapper internals
After calling global command iohtee-abi-wrapper
$ iohtee-abi-wrapper -o ./generated ./abi/*
you will get a TS wrapper file.
Say you have contract ABI with name Unidirectional
, in this case TS wrapper classname will be UnidirectionalContract
Importing:
import {
CtorParams,
UnidirectionalContract,
} from './generated/UnidirectionalContract'
Constructor:
constructor(deployedContractAddress: `0x${string}`, params: CtorParams)
deployedContractAddress
is the blockchain contract address which will be used for interacting via TS-wrapper.CtorParams
object type consists of:
{
httpRpcUrl: string // RPC URL (e.g. Alchemy, Infura...) like https://rpc-amoy.polygon.technology
networkId: number // Network ID or Chain ID like 80002 for Polygon Amoy
mnemonic: string // 12-word seed mnemonic phrase
hdPath: `m/44'/60'/${string}` // BIP44 HDPath of account like m/44'/60'/0'/0/0 for the first account for the given seed
}
Generated HTML documentation for TS wrapper be like
TODO
- add postprocess with prettier and autodetecting of prettierrc
- TS-wrapper docs autogen
- add errors and library references handling
- generate d.ts and min.js wrapper files
- add solidity comments to wrapper
License
Apache-2.0