# @blockcoders/harmony-providers

> This library provides a collection of methods to interact with the Harmony blockchain.

Latest version **1.0.0** (published 2022-04-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @blockcoders/harmony-providers
pnpm add @blockcoders/harmony-providers
yarn add @blockcoders/harmony-providers
bun add @blockcoders/harmony-providers
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-04-21 |
| First published | 2022-04-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 80.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | fer@blockcoders.io |
| Maintainers | fsirni, jarcodallo |

## Links

- npm: https://www.npmjs.com/package/@blockcoders/harmony-providers
- Homepage: https://github.com/blockcoders/sdk#readme
- Issues: https://github.com/blockcoders/sdk/issues
- npm.io page: https://npm.io/package/@blockcoders/harmony-providers

## Dependencies (2)

- [@ethersproject/networks](https://npm.io/package/@ethersproject/networks.md) ^5.6.1
- [@ethersproject/providers](https://npm.io/package/@ethersproject/providers.md) ^5.6.2

## Recent versions

- 1.0.0 (latest) — 2022-04-21

## README

# Harmony RPC Providers

This library provides a collection of methods to interact with the Harmony blockchain.

Currently under developement 🤓

## Install

```sh
npm i @blockcoders/harmony-providers
```

## Usage

### Node

```typescript
// JavaScript
const { HarmonyProvider } = require('@blockcoders/harmony-providers')

// TypeScript
import { HarmonyProvider } from '@blockcoders/harmony-providers'
```

## Harmony SDK

Expected Methods:
| Method | Description |
| ------------- | ------------- |
| getBlockNumber | Gets the last block number. |
| getBlock | Gets the block data by block number or block hash (retrieves transactions hashes only). |
| getBlockWithTransactions | Gets the block data by block number or block hash and retrieve the transactions data. |
| getTransaction | Gets the transaction data by transaction hash. |

### Initializing

```typescript
import { HarmonyProvider, HMY_TESTNET_NETWORK } from '@blockcoders/harmony-providers'

const provider = new HarmonyProvider(HMY_TESTNET_NETWORK) // Use HMY_NETWORK to interact with Harmony's mainnet
```

### Methods

#### getBlockNumber

Returns the last block number on the blockchain.

```ts
import { HarmonyProvider, HarmonyProviderMethods, HMY_TESTNET_NETWORK } from '@blockcoders/harmony-providers'

const provider = new HarmonyProvider(HMY_TESTNET_NETWORK)
const blockNumber = await provider.getBlockNumber()
// Executing the perform method 
const otherWayToGetBlockNumber = await provider.perform(HarmonyProviderMethods.getBlockNumber, {})
```
#### getBlock and getBlockWithTransactions

Returns the block data. The block can be searched by it's hash or number. It can retrieve the block transactions data or just the transactions hashes.

```ts
import { HarmonyProvider, HarmonyProviderMethods, HMY_TESTNET_NETWORK } from '@blockcoders/harmony-providers'

const provider = new HarmonyProvider(HMY_TESTNET_NETWORK)

// Searching with number

const searchByTag = "0x47db8e" // The block number can be an hexadecimal, number or "latest"
const block = await provider.getBlock(searchByTag)
const blockWithTransactionsData = await provider.getBlockWithTransactions(searchByTag)

// Searching with hash

const searchByHash = "0xd5258b03ae6b7d1ad8e932bf1aed6257241101e98be7ac6dab74013f267596de"
const sameBlock = await provider.getBlock(searchByHash)
const sameBlockWithTransactionsData = await provider.getBlockWithTransactions(searchByHash)

// Using perform
const params = {
    blockTag: "0x47db8e", // Change this property for blockHash if you want touse the hash to search the block
    includeTransactions: true // This will indicate the method whether or not to get the transactions data
}
const someBlock = await provider.perform(HarmonyProviderMethods.getBlock, params)
```
#### getTransaction

Returns the transaction data by hash.

```ts
import { HarmonyProvider, HarmonyProviderMethods, HMY_TESTNET_NETWORK } from '@blockcoders/harmony-providers'

const provider = new HarmonyProvider(HMY_TESTNET_NETWORK)

const txHash = "0x371ec289c5973c16d58cf600f8f2ce040fe8b429a6007976040d55a1759b8993"
const transaction = await provider.getTransaction(txHash)

// Executing the perform method 
const params = {
    transactionHash: "0x371ec289c5973c16d58cf600f8f2ce040fe8b429a6007976040d55a1759b8993"
}
const otherWayToGetBlockNumber = await provider.perform(HarmonyProviderMethods.getTransaction, params)
```

## Change Log

See [Changelog](CHANGELOG.md) for more information.

## Contributing

Contributions welcome! See [Contributing](CONTRIBUTING.md).

## Collaborators

- [**Jose Ramirez**](https://github.com/0xslipk)
- [**Brian Zuker**](https://github.com/bzuker)
- [**Fernando Sirni**](https://github.com/fersirni)

## Acknowledgements

This project was kindly sponsored by [Harmony](https://www.harmony.one/).

## License

Licensed under the MIT - see the [LICENSE](LICENSE) file for details.

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