An open API service indexing awesome lists of open source software.

https://github.com/jellydn/use-wait-for-transaction-hash

Simple hook for getting transaction status from the ETH network.
https://github.com/jellydn/use-wait-for-transaction-hash

binance-smart-chain ethereum hacktoberfest hooks-api react

Last synced: 2 months ago
JSON representation

Simple hook for getting transaction status from the ETH network.

Awesome Lists containing this project

README

        

# Welcome to use-wait-for-transaction-hash 👋

[![Version](https://img.shields.io/npm/v/use-wait-for-transaction-hash.svg)](https://npmjs.org/package/use-wait-for-transaction-hash)
[![Downloads/week](https://img.shields.io/npm/dw/use-wait-for-transaction-hash.svg)](https://npmjs.org/package/use-wait-for-transaction-hash)
![Prerequisite](https://img.shields.io/badge/node-%3E%3D10-blue.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#)
[![Twitter: jellydn](https://img.shields.io/twitter/follow/jellydn.svg?style=social)](https://twitter.com/jellydn)

> Simple hook for getting transaction status from the ETH network.

## ✨ [Demo](https://use-wait-for-transaction-hash.productsway.com/)

## Prerequisites

- React >=16.8

## Install

```sh
yarn add use-wait-for-transaction-hash
```

## Usage

Simple usage with `Notify component`

```js
import { useWaitForTransactionHash } from 'use-wait-for-transaction-hash';

interface Props {
providerUrl: string;
transactionHash: string;
}

function Notify({ providerUrl, transactionHash }: Props) {
const { status } = useWaitForTransactionHash({
hash: transactionHash,
providerUrl,
});
return (


Hash: {transactionHash}

Provider Url: {providerUrl}

Status: {status}


);
}

function App() {
const [toggle, setToggle] = useState(false);

return (



(toggle ? setToggle(false) : setToggle(true))}>
Toggle the transaction hash




);
}
```

For more detail, please check the example app (`example` folder),

## Recipes

Usage with react-hot-toast

```js
import { useEffect } from 'react';
import { useWaitForTransactionHash } from 'use-wait-for-transaction-hash';
import toast, { Toaster } from 'react-hot-toast';

function Notify({ providerUrl, transactionHash }: Props) {
const { status } = useWaitForTransactionHash({
hash: transactionHash,
providerUrl,
});

// measure performance base on the transaction status
useEffect(() => {
switch (status) {
case 'SUCCESS':
toast.success('This is a success transaction');
break;

case 'FAILED':
toast.error('This is a failed transaction');
break;
default: // PENDING
}
}, [status]);

// clear previous toast message and show checking information
useEffect(() => {
toast.dismiss();
toast.loading('Checking...' + transactionHash);
}, [transactionHash]);

return (


Hash: {transactionHash}

Provider Url: {providerUrl}

Status: {status}


);
}

function App() {
return (




);
}
```

## Run tests

```sh
yarn test
```

## Author

👤 **Huynh Duc Dung**

- Website: https://productsway.com/
- Twitter: [@jellydn](https://twitter.com/jellydn)
- Github: [@jellydn](https://github.com/jellydn)

## Stargazers 🌟

[![Stargazers repo roster for jellydn/use-wait-for-transaction-hash](https://reporoster.com/stars/jellydn/use-wait-for-transaction-hash)](https://github.com/jellydn/use-wait-for-transaction-hash/stargazers)

## Show your support

Give a ⭐️ if this project helped you!

[![support us](https://img.shields.io/badge/become-a patreon%20us-orange.svg?cacheSeconds=2592000)](https://www.patreon.com/jellydn)

---

_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_