Tanishq Singh
1 min readFeb 16, 2023

--

How to create a NANO (XNO) wallet using nanojs
## _**How wallet works.**_
- Wallet is a collection of accounts
- Wallet is generally generated using a seed.
- Structure
- ```sh
`seed` (wallet)
├── 0 (index)
│ └── `private key`
│ └── public key
│ └── `address`

├── 1 (index)
. └── `private key`
. └── public key
. └── `address`

```

<br />

## _**Create a wallet in Node**_
1. Install [**nanojs**](https://www.npmjs.com/package/@tanishq-singh/nanojs) package _(Only in node)_
```sh
npm i @tanishq-singh/nanojs
# or
yarn add @tanishq-singh/nanojs
```

2. _**Import package**_
```ts
// In Node
import nanojs from "@tanishq-singh/nanojs"; // or
const nanojs = require("@tanishq-singh/nanojs");

// In Deno
import nanojs from './deps.ts'; // or
import nanojs from 'https://deno.land/x/nanojs/mod.ts';
```

3. _**Create Wallet**_

a. **Fresh Wallet**

```ts
const wallet = await create_wallet({ });
console.log(wallet);
```

```sh
{
seed: "a4eb1443df8cb67d7b3a869412e8f9c89734962df0711af344a9e7c44afb145e",
accounts: [
{
index: 0,
private_key: "E4A3C94BBD0592070661002E253DDAD5B1345801AFC3175DBDCE923CB6FEEAEC",
public_key: "C7537142ED0ADE795D6B73008B24A9BD31A09E477A83BCB9B7A6B0B3A7EB5418",
address: "nano_3jtmg73gt4pyh7gppwr1jekcmhbjn4h6gyn5qkwuhboipgmypo1rdzbbadxa"
}
]
}
```

b. **Use already created wallet with seed**

```ts
const wallet = await create_wallet({ seed: "5b4b36a524c213a1ef891af31dc5b3071c59c12e36b7fe14f692052b2ea9c74a", till_index: 2 });
console.log(wallet);
```

```sh
{
seed: "5b4b36a524c213a1ef891af31dc5b3071c59c12e36b7fe14f692052b2ea9c74a",
accounts: [
{
index: 0,
private_key: "5C7F0183303876298751DF2482F1DB6DF27C789E1EEE42598B9BAD35B12130D2",
public_key: "2BF49EAF6AEF19BCFEBF40A05D7782838957C212CE3AC1B441023A5029DDA4E0",
address: "nano_1cznmtqpoursqmzdyi71dour71wbcz337mjtr8t641jtc1nxub915abj3pcm"
},
{
index: 1,
private_key: "325A1C6B0AC52350BD4DE2A15965753DB397E278DDE4A377346916A8DB7C8496",
public_key: "4ADDA484090D7B14B24EE56B86D7DAB1F8694FE7E18133317C126DBD5A5AD121",
address: "nano_1kpxnk41k5du4ks6xsddiudxoehrf79yhre38erqr6mfqof7onb3om5hdqax"
},
{
index: 2,
private_key: "5B573170C262F3243305880F385B61A20AA5C66757F55A76E51DCD5B4EF2C66C",
public_key: "D8818A1D542976846759F2EE6A5D90D174BA089049B42961EC4FC2663BA92732",
address: "nano_3p63jagoacdpijmomwqgfbgs3ndnqa6b1kfn77iyrmy4erxtkbskfws7pujn"
}
]
}
```

--

--