# eth-receiver

Latest version **1.0.2** (published 2020-10-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install eth-receiver
pnpm add eth-receiver
yarn add eth-receiver
bun add eth-receiver
```

## 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.2 |
| Published | 2020-10-22 |
| First published | 2020-10-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | xsubject |
| Maintainers | xsubject |
| Keywords | eth, receiver, receive, ethereum, purchase, store |

## Links

- npm: https://www.npmjs.com/package/eth-receiver
- Repository: https://github.com/xsubject/eth-receiver
- Homepage: https://github.com/xsubject/eth-receiver#readme
- Issues: https://github.com/xsubject/eth-receiver/issues
- npm.io page: https://npm.io/package/eth-receiver

## Dependencies (2)

- [web3](https://npm.io/package/web3.md) ^1.3.0
- [sqlite3](https://npm.io/package/sqlite3.md) ^5.0.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-10-22
- 1.0.1 — 2020-10-22
- 1.0.0 — 2020-10-22

## README

# eth-receiver
A library that will help you receive ethereum in your project. 
This is an attempt to make your life a little easier, so you don't need to think about the database, this project creates a sqlite3 database on its own. 
But you must save the data you need, since in the future it is planned to destroy any irrelevant data in this database.

# Install
```
npm install eth-receiver
```

# Usage
```js
const Receiver = require('eth-receiver');

// You must provide the address of the websocket based node. It is recommended to use infura if you do not have a personal node
// new Receiver(node, value_for_confirm_tx, database_path)
const receiver = new Receiver('wss://ropsten.infura.io/ws/v3/53aa34f225694dca9e4fdcc4eb97c143', 12, 'receiver.db');
```

Use `receiver.onInit` to make sure the database is ready to go. However, this is not always necessary.
```js
receiver.onInit(() => {
...
})
```

Use the `newBlock` event to respond to new blocks.
```js
receiver.on('newBlock', blockHeader => {
  console.log("Block", blockHeader.hash, "created");
})
```

Create a disposable address and link the desired top-up amount to it. Pass the new address and amount to the user
```js
receiver.createAddress(100).then(account => {
  console.log("Send", account.amount, "wei to", account.address);
});
```

Use the `createdTransaction` event to react to new transactions in at least one block. You can already collect these coins and react as you see fit. However, this is not safe.
```js
receiver.on("createdTransaction", context => {
  console.log("tx", context.tx.hash, "created with id", context.row.id, "and wait to confirm");
});
```

The `confirmedTransaction` event will be triggered when the transaction receives more than `[value_for_confirm_tx from constructor]` confirmations
```js
receiver.on("confirmedTransaction", async (context) => {
  console.log("tx", context.tx.hash, "confirmed, id", context.row.id);

  // use `context.collect` to collect all coins for any other wallet
  let tx = await context.collect('0x0000000000000000000000000000000000000000');
  console.log("Created collect tx", tx);
});
```

# Example

```js
const Receiver = require('eth-receiver');
const receiver = new Receiver('wss://ropsten.infura.io/ws/v3/53aa34f225694dca9e4fdcc4eb97c143', 3, 'receiver.db');


receiver.onInit(() => {
  receiver.on('newBlock', blockHeader => {
    console.log("Block", blockHeader.hash, "created");
  })

  receiver.createAddress(100).then(account => {
    console.log("Send", account.amount, "wei to", account.address);
  });

  receiver.on("createdTransaction", context => {
    console.log("tx", context.tx.hash, "created with id", context.row.id, "and wait to confirm");
  });

  receiver.on("confirmedTransaction", async (context) => {
    console.log("tx", context.tx.hash, "confirmed, id", context.row.id);

    let tx = await context.collect('0x0000000000000000000000000000000000000000');
    console.log("Created collect tx", tx);
  });
})

```

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