# nano-wallet-js

> SDK for developers to create and interact with Nanocurrency wallet easily

Latest version **0.2.1** (published 2023-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install nano-wallet-js
pnpm add nano-wallet-js
yarn add nano-wallet-js
bun add nano-wallet-js
```

## 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.2.1 |
| Published | 2023-10-10 |
| First published | 2023-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 92.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | anarkrypto |
| Maintainers | anarkrypto |
| Keywords | nanocurrency, wallet, sdk, js |

## Links

- npm: https://www.npmjs.com/package/nano-wallet-js
- Repository: https://github.com/nanopay/nano-wallet-js
- Homepage: https://github.com/nanopay/nano-wallet-js/tree/main/#readme
- Issues: https://github.com/nanopay/nano-wallet-js/issues
- npm.io page: https://npm.io/package/nano-wallet-js

## Dependencies (2)

- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.1.1
- [nanocurrency](https://npm.io/package/nanocurrency.md) ^2.5.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.2.1 (latest) — 2023-10-10
- 0.2.0 — 2023-09-20
- 0.2.0-alpha.10 — 2023-09-19
- 0.2.0-alpha.9 — 2023-09-19
- 0.2.0-alpha.8 — 2023-09-19
- 0.2.0-alpha.7 — 2023-09-19
- 0.2.0-alpha.6 — 2023-09-19
- 0.2.0-alpha.5 — 2023-09-19
- 0.2.0-alpha.4 — 2023-09-19
- 0.2.0-alpha.3 — 2023-09-19
- 0.2.0-alpha.2 — 2023-09-19
- 0.2.0-alpha.1 — 2023-09-19
- 0.1.0 — 2023-09-09
- 0.1.0-alpha.3 — 2023-07-31
- 0.1.0-alpha.2 — 2023-07-31
- … 2 more at https://npm.io/package/nano-wallet-js/versions

## README

# nano-wallet-js

SDK for developers to create and interact with Nanocurrency wallets easily with Typescript or Javascript

## Why to use it ?

- 🎉 Easy to use, no need to configure RPC calls
- 🧑‍💻 Allows you to configure multiple RPC and Work Servers separately.
- 👷 Automatic fallback when a request fails
- 🌐 Runtime agnostic: Compatible with Node.js, Browser, EDGE, Bun, Deno and others.
- ⚡️ Efficient and agnostic state management allows you to store the wallet state with your favorite tool and start the instance with the previous state.
- 🔒️ Safe and non-custodial: Your privateKey is never shared with RPC or any server, all signatures and key derivation is made on client side by [nanocurrency.js library](https://github.com/marvinroger/nanocurrency-js)

## How to use it

#### Install nano-wallet-js package

```
npm install nano-wallet-js
```

#### Init the Wallet instance and sync:

```js
import NanoWallet from 'nano-wallet-js';

const config = {
	privateKey: '000AAFF...', // The privateKey (secret) of your wallet (not the SEED, neither the MNEMONIC)
	rpcUrls: ['http://[::1]:7076'], // A string or an array of RPC addresses
	workerUrls: ['http://[::1]:7076'], // A string or an array of RPC Worker Server. Can be the same as rpcUrls
	representative:
		'nano_3kc8wwut3u8g1kwa6x4drkzu346bdbyqzsn14tmabrpeobn8igksfqkzajbb', // representative account
	debug: true, // show console log message (optional)
};

const wallet = new NanoWallet(config);

await wallet.sync();
```

#### Optionally, init with a state:

```js
// It is only needed at wallet initialization.
// You can use a Database, Filesystem, KV, Redux or whatever...
const state = await getFromMyStorage();

const wallet = new NanoWallet(config, state);

// Subscribe to state changes to persist in your storage
wallet.subscribe(async state => {
	await saveIntoMyStorage(state);
});
```

### Properties:

- `wallet.account`: Your wallet account / address
- `wallet.balance`: Your wallet balance in raws
- `wallet.receivable`: Total amount to be received
- `wallet.receivableBlocks`: Array of pending blocks to receive with blockHash and amount
- `wallet.frontier`: Previous block hash (your last transaction)
- `wallet.representative`: The representative you set when initing the instance
- `wallet.currentRepresentative`: Your current representative. Make a transaction or call `.setRepresentative()` to update.

### Methods:

**Sync**: Force wallet synchronization, updating frontier, balance, receivable and representative.

```js
await wallet.sync();
console.log(wallet.frontier, wallet.balance, ...)
```

**Get Receivables**:
Returns an array containing the blocks that have not been received yet by this account. Each block contains
the `hash` property which you need to receive it using **Receive**.

```js
await wallet.getReceivable();
console.log(wallet.receivable, wallet.receivableBlocks);
```

**Receive**: Receive amount manually. This process will be automated in next releases.

```js
for (const receivable of wallet.receivableBlocks) {
	const { hash } = await wallet.receive(receivables.blockHash);
}
```

**Send**: Send amount in raws to another wallet.

```js
const to = 'nano_1abcd...';
const amount = '1000000000000000000000000000'; // 0.001 Nano
const { hash } = await wallet.send(to, amount);

// print the updated balance
console.log('Balance:', wallet.balance);
```

**Sweep**: Send all balance to another wallet (Careful!)

```js
const to = 'nano_3efgh...';
const { hash } = await wallet.sweep(to);
```

**Set Representative**: Set a new representative

```js
const rep = 'nano_4ijk1mno...';
await wallet.setRepresentative(rep);

// print
console.log(wallet.representative, wallet.currentRepresentative);
```

More methods soon...

## 🚧 Work in progress!

This is a initial release, not recommended for production use yet.

## Donate Ӿ

If you find this library useful and want to support its development please consider donating:
**nano_3dqh8z8ncswmf7151gryu7mqpwbw4f68hi7d8g433omtuabfi438etyyp9ik**

<kbd><img src="https://i.ibb.co/Gs6yhv2/nano-wallet-js-qr-code.png" width="200px" height="200px" /></kbd>

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