@etn-sc/web3-eth-contract
v4.1.3
Published
Web3 module to interact with Electroneum smart contracts.
Downloads
10
Readme
web3.js - Eth Contract Package
This is a sub-package of @etn-sc/web3.js.
@etn-sc/web3-eth-contract
contains the contract package used in @etn-sc/web3-eth
.
Installation
You can install the package using NPM
Using NPM
npm install @etn-sc/web3-eth-contract
Getting Started
- :writing_hand: If you have questions submit an issue
Prerequisites
Usage
You can initialize the typesafe Contract API instance with the following.
import { Contract } from '@etn-sc/web3-eth-contract';
const abi = [...] as const;
const contract = new Contract(abi);
- We prefer that you use
web3.eth.Contract
API in normal usage. - The use of
as const
is necessary to have fully type-safe interface for the contract. - As the ABIs are not extensive in size, we suggest declaring them
as const
in your TS project. - This approach is more flexible and seamless compared to other approaches of off-line compiling ABIs to TS interfaces (such as TypeChain.
Compatibility
We have tested the Typescript interface support for the ABIs compiled with solidity version v0.4.x
and above. If you face any issue regarding the contract typing, please create an issue to report to us.
The Typescript support for fixed length array types are supported up 30 elements. See more details here. This limitation is only to provide more performant developer experience in IDEs. In future we may come up with a workaround to avoid this limitation. If you have any idea feel free to share.
Package.json Scripts
| Script | Description |
| ---------------- | -------------------------------------------------- |
| clean | Uses rimraf
to remove dist/
|
| build | Uses tsc
to build package and dependent packages |
| lint | Uses eslint
to lint package |
| lint:fix | Uses eslint
to check and fix any warnings |
| format | Uses prettier
to format the code |
| test | Uses jest
to run unit tests |
| test:integration | Uses jest
to run tests under /test/integration
|
| test:unit | Uses jest
to run tests under /test/unit
|