# @huobiwallet-js/contract

> contract libraries for huobiwallet

Latest version **0.0.12** (published 2020-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @huobiwallet-js/contract
pnpm add @huobiwallet-js/contract
yarn add @huobiwallet-js/contract
bun add @huobiwallet-js/contract
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.12 |
| Published | 2020-12-29 |
| First published | 2020-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 15.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | huobichain |

## Links

- npm: https://www.npmjs.com/package/@huobiwallet-js/contract
- npm.io page: https://npm.io/package/@huobiwallet-js/contract

## Dependencies (5)

- [@huobiwallet-js/utils](https://npm.io/package/@huobiwallet-js/utils.md) ^0.0.12
- [@huobiwallet-js/crypto](https://npm.io/package/@huobiwallet-js/crypto.md) ^0.0.12
- [@huobiwallet-js/account](https://npm.io/package/@huobiwallet-js/account.md) ^0.0.12
- [@huobiwallet-js/network](https://npm.io/package/@huobiwallet-js/network.md) ^0.0.12
- [@huobiwallet-js/transaction](https://npm.io/package/@huobiwallet-js/transaction.md) ^0.0.12

## Recent versions

- 0.0.12 (latest) — 2020-12-29

## README

# @huobiwallet-js/contract

This package provides a collection of apis to create, deploy, and interact with smart contracts. In Huobiwallet, smart contracts all fully EVM compatible and the formats and terminologies match 1-to-1 with EVM smart contracts.

## Installation

```
npm install @huobiwallet-js/contract
```

## Usage



Estimate gas for contract methods
```javascript
const options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000

contract.methods.getCount().estimateGas(options1).then(gas => {
  console.log('gas required for getCount is ' + hexToNumber(gas));
});
```

Call contract read-only methods. Huobiwallet uses 1 Gwei gas price and gas limit of 21000 by default. Use the estimate gas api to correctly set the gas limit.
```javascript
const options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000
let options2 = { gasPrice: 1000000000, gasLimit: 21000 }; // setting the default gas limit, but changing later based on estimate gas

contract.methods.getCount().estimateGas(options1).then(gas => {
  options2 = {...options2, gasLimit: hexToNumber(gas)};
  contract.methods.getCount().call(options2).then(count => {
    console.log('counter value: ' + count);
  });
});
```

Invoking contract modification methods using `send` api. Need to add a signing account to the contract wallet, otherwise `send` api will not work.
```javascript
const options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000
let options2 = { gasPrice: 1000000000, gasLimit: 21000 }; // setting the default gas limit, but changing later based on estimate gas

contract.wallet.addByPrivateKey('1f054c21a0f57ebc402c00e14bd1707ddf45542d4ed9989933dbefc4ea96ca68');

contract.methods.incrementCounter().estimateGas(options1).then(gas => {
  options2 = {...options2, gasLimit: hexToNumber(gas)};
  contract.methods.incrementCounter().send(options2).then(response => {
    console.log(response.transaction.receipt);
  });
});
```

All the above apis can also be asynchronously executed using `async` and `await`.

---
_Source: https://npm.io/package/@huobiwallet-js/contract · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
