GithubHelp home page GithubHelp logo

simple-nano-wallet-js's Introduction

Simple Nano Wallet JS

Simple nano wallet with in memory key managment and client side signatures.
Compatible with any nano node RPC & Websocket. Made by Nanswap Nodes.

Features

  • Send & Receive nano
  • Auto receive wallet's incoming blocks (requires websocket)
  • Compatible with Banano, DogeNano and any nano-node network with custom prefix & decimal
  • Receive all receivable blocks for an account
  • Create wallet from seed or from random entropy
  • Create derived accounts

Installation
Using npm

npm install simple-nano-wallet-js

Using yarn

yarn add simple-nano-wallet-js

Usage:
Create new wallet

const { Wallet } = require('simple-nano-wallet-js');
const { wallet: walletLib} = require('multi-nano-web')

let seed = walletLib.generateLegacy().seed // save & backup it somewhere!
// initialize wallet
const wallet = new Wallet({
            RPC_URL: 'http://127.0.0.1:7076',
            WORK_URL: 'http://127.0.0.1:7076',
            WS_URL: `ws://127.0.0.1:7078`,
            seed: seed,
            defaultRep: "nano_1banexkcfuieufzxksfrxqf6xy8e57ry1zdtq9yn7jntzhpwu4pg4hajojmq",
        })

// Generate 10 derived accounts
let accounts = wallet.createAccounts(10)
// ["nano_3g5hpb4kwqgakt4cx11ftq6xztx1matfhgkmhunj3sx4f4s3nwb6hfi3nts1", ... ]

Auto Receive
By default, when a websocket is provided, receivable blocks for all wallet accounts will be processed automatically.
To disable this feature, set autoReceive to false when initializing the wallet.

Manually Receive

// receive all receivable blocks for an account
let hashesReceive = await wallet.receiveAll("nano_3g5hpb4kwqgakt4cx11ftq6xztx1matfhgkmhunj3sx4f4s3nwb6hfi3nts1")

Send

// send 0.001 nano from nano_3g5hp... to nano_3g5hp...
let hash = await wallet.send({
        source: "nano_3g5hpb4kwqgakt4cx11ftq6xztx1matfhgkmhunj3sx4f4s3nwb6hfi3nts1", // must be in wallet. 
        destination: "nano_3g5hpb4kwqgakt4cx11ftq6xztx1matfhgkmhunj3sx4f4s3nwb6hfi3nts1",
        amount: wallet.megaToRaw(0.001),
})
        

Custom networks

let headerAuth = { // custom header for authentification
     "nodes-api-key": process.env.NODES_API_KEY
}

// DogeNano Wallet
const walletXDG = new Wallet({
            RPC_URL: 'https://nodes.nanswap.com/XDG',
            WORK_URL: 'https://nodes.nanswap.com/XDG',
            WS_URL: `wss://nodes.nanswap.com/ws/?ticker=XDG&api=${process.env.NODES_API_KEY}`,
            seed: seedXDG,
            defaultRep: "xdg_1e4ecrhmcws6kwiegw8dsbq5jstq7gqj7fspjmgiu11q55s6xnsnp3t9jqxf",
            prefix: 'xdg_',
            decimal: 26,
            customHeaders: headerAuth,
            wsSubAll: false, 
        })
// Banano Wallet
const walletBAN = new Wallet({
            RPC_URL: 'https://nodes.nanswap.com/BAN',
            WORK_URL: 'https://nodes.nanswap.com/BAN',
            WS_URL: `wss://nodes.nanswap.com/ws/?ticker=BAN&api=${process.env.NODES_API_KEY}`,
            seed: seedBAN,
            defaultRep: "ban_1banexkcfuieufzxksfrxqf6xy8e57ry1zdtq9yn7jntzhpwu4pg4hajojmq",
            prefix: 'ban_',
            decimal: 29,
            customHeaders: headerAuth,
            wsSubAll: false
        })

This lib is intended for small project (<5000 accounts), for a more scablable system, it is recommended to use a database to store the accounts keys.

Credits to nanocurrency-web for nano toolkit.

simple-nano-wallet-js's People

Contributors

benskalz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

myecoria

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.