# @huobiwallet-js/core

> huobiwallet core package

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

## Install

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

## Health

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

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

Warnings: low downloads; 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 | 6 |
| Unpacked size | 830.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | huobichain |

## Links

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

## Dependencies (6)

- [@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/contract](https://npm.io/package/@huobiwallet-js/contract.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/core

This package provides a collection of apis to interact with Huobiwallet blockchain.

## Installation

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

## Usage

Create a Huobiwallet instance connecting to testnet

```javascript
const { Huobiwallet } = require('@huobiwallet-js/core');
const {
  ChainID,
  ChainType,
  hexToNumber,
  numberToHex,
  fromWei,
  Units,
  Unit,
} = require('@huobiwallet-js/utils');

const Heco = new Huobiwallet(
    'https://http-testnet.hecochain.com/',
    {
        chainType: ChainType.Huobi,
        chainId: ChainID.HecoTestnet,
    },
);
```

Getting balance of account `0xB26cdfEC309d01C2Cc526B14D4C2A0Ecab402702`
```javascript
Heco.blockchain
  .getBalance({ address: '0xB26cdfEC309d01C2Cc526B14D4C2A0Ecab402702' })
  .then((response) => {
    console.log('balance in ONEs: ' + fromWei(hexToNumber(response.result), Units.ether));
  });
```

Getting the latest block number
```javascript
Heco.blockchain.getBlockNumber().then((response) => {
  console.log('current block number: ' + hexToNumber(response.result));
});
```

Getting the block using block hash
```javascript
Heco.blockchain
  .getBlockByHash({
    blockHash: '0x08c46ae7249362a7d1f602d44c5a81f33ebdab6a7dcb6068f99610b57911aafd',
  })
  .then((response) => {
    console.log(response.result);
  });
```

Getting the block using block number
```javascript
Heco.blockchain
  .getBlockByNumber({
    blockNumber: numberToHex(422635),
  })
  .then((response) => {
    console.log(response.result);
  });
```

Getting the transaction using hash
```javascript
Heco.blockchain
  .getTransactionByHash({
    txnHash: '0x56c73eb993b18dc04baacec5c2e9d1292a090f6a978a4a1c461db5255fcbc831',
  })
  .then((response) => {
    console.log(response.result);
  });
```

Getting the transaction receipt
```javascript
Heco.blockchain
  .getTransactionReceipt({
    txnHash: '0x56c73eb993b18dc04baacec5c2e9d1292a090f6a978a4a1c461db5255fcbc831',
  })
  .then((response) => {
    console.log(response.result);
  });
```

Getting the cross-shard transaction receipt
```javascript
Heco.blockchain
  .getCxReceiptByHash({
    txnHash: '0xcd36a90ff5d5373285c2896ba7bbcd3f5324263c0cb8ecfb7cad2f5fc2fbdbda',
    shardID: 1,
  })
  .then((value) => {
    console.log(value.result);
  });
```

Getting the deployed smart contract code
```javascript
Heco.blockchain
  .getCode({
    address: '0x08AE1abFE01aEA60a47663bCe0794eCCD5763c19',
    blockNumber: 'latest',
  })
  .then((response) => {
    console.log(response.result);
  });
```

Getting the transaction count of an account
```javascript
Heco.blockchain
  .getTransactionCount({
    address: '0xB26cdfEC309d01C2Cc526B14D4C2A0Ecab402702',
  })
  .then((response) => {
    console.log(hexToNumber(response.result));
  });
```

Getting the shard structure and details
```javascript
Heco.blockchain.getShardingStructure().then((response) => {
  console.log(response.result);
});
```

Transferring funds using `sendTransaction`
```javascript
// key corresponds to one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance
Heco.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');

async function transfer() {
  const txn = Heco.transactions.newTx({
    to: '0xB26cdfEC309d01C2Cc526B14D4C2A0Ecab402702',
    value: new Unit(1).asEther().toWei(),
    // gas limit, you can use string
    gasLimit: '21000',
    // send token from shardID
    shardID: 0,
    // send token to toShardID
    toShardID: 0,
    // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
    gasPrice: new Heco.utils.Unit('1').asGwei().toWei(),
  });

  // sign the transaction use wallet;
  const signedTxn = await Heco.wallet.signTransaction(txn);
  const txnHash = await Heco.blockchain.sendTransaction(signedTxn);
  console.log(txnHash.result);
}

transfer();
```

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