# @harmony-js/core

> harmony core package

Latest version **0.1.57** (published 2021-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @harmony-js/core
pnpm add @harmony-js/core
yarn add @harmony-js/core
bun add @harmony-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.1.57 |
| Published | 2021-02-10 |
| First published | 2019-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 234.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | neeboo@firestack.one |
| Maintainers | ghostcorn, jhwon0820, gupadhyaya |

## Links

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

## Dependencies (7)

- [@harmony-js/utils](https://npm.io/package/@harmony-js/utils.md) 0.1.56
- [@harmony-js/crypto](https://npm.io/package/@harmony-js/crypto.md) 0.1.56
- [@harmony-js/account](https://npm.io/package/@harmony-js/account.md) 0.1.57
- [@harmony-js/network](https://npm.io/package/@harmony-js/network.md) 0.1.56
- [@harmony-js/staking](https://npm.io/package/@harmony-js/staking.md) 0.1.56
- [@harmony-js/contract](https://npm.io/package/@harmony-js/contract.md) 0.1.56
- [@harmony-js/transaction](https://npm.io/package/@harmony-js/transaction.md) 0.1.56

## Recent versions

- 0.1.57 (latest) — 2021-02-10
- 0.1.58 (next) — 2022-07-06
- 0.1.41-alpha.1 (canary) — 2020-05-04
- 0.1.56 — 2020-11-22
- 0.1.55 — 2020-09-29
- 0.1.54 — 2020-09-07
- 0.1.53 — 2020-08-19
- 0.1.52 — 2020-08-14
- 0.1.51 — 2020-08-06
- 0.1.50 — 2020-07-29
- 0.1.49 — 2020-07-16
- 0.1.48 — 2020-07-13
- 0.1.47 — 2020-07-07
- 0.1.46 — 2020-06-12
- 0.1.45 — 2020-06-06
- … 80 more at https://npm.io/package/@harmony-js/core/versions

## README

# @harmony-js/core

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

## Installation

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

## Usage

Create a Harmony instance connecting to testnet

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

const hmy = new Harmony(
    'https://api.s0.b.hmny.io/',
    {
        chainType: ChainType.Harmony,
        chainId: ChainID.HmyTestnet,
    },
);
```

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

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

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

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

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

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

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

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

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

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

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

async function transfer() {
  const txn = hmy.transactions.newTx({
    to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
    value: new Unit(1).asOne().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 hmy.utils.Unit('1').asGwei().toWei(),
  });

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

transfer();
```

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