Giter Club home page Giter Club logo

nanopay's Introduction

NANOPAY

NanoPay is a simple and easy-to-use Node.js library for interacting with the Nano cryptocurrency network. This library allows you to perform various wallet-related tasks such as sending Nano, fetching account history, and more.

Install


npm i nanopay

Usage

// Import the module
const nano = require('nanopay');

// Set the Nano node URL
const nanoNode = 'https://nault.nanos.cc/proxy';
nano.init(nanoNode);

// Define the secret key
const secretKey = '12d2dde836172e21fcfbff2dd94c83e8ae8e53979a90e13def8f010a767e5d0c';

async function main() {
    // Convert raw value to Nano
    const convertedRaw = await nano.rawToNano(1000000000000000000000000000000);
    console.log('Converted raw value:', convertedRaw);

    // Generate an address from the secret key
    const { address, publicKey } = await nano.secretKeyDecode(secretKey);
    console.log('Address:', address);

    // Get account data (addressInfo takes an address and an optional number of recent transactions to load)
    const accountData = await nano.addressInfo(address);
    console.log('Account data:', accountData);

    // Cache PoW for the next transaction using the account's frontier
    const blockToCache = accountData.info.frontier;
    await nano.cachePOW(blockToCache);

    // Receive pending transactions
    const receivedTxn = await nano.fetchPending(secretKey);
    if (receivedTxn.hash) {
        console.log('Received transaction:', receivedTxn);
    }

    // Send Nano to an address
    const recipientAddress = 'nano_3gj8wk5r3wqonhirr81mxyhy5bumj4t3x1qopgqpsj3q3ik4p7ucg7trkx78';
    const sendAmount = 0.0001;
    const sentTxn = await nano.send(secretKey, recipientAddress, sendAmount);
    if (sentTxn.hash) {
        console.log('Sent transaction:', sentTxn);
    }

    // Send a percentage of Nano to an address
    const sendPercentage = 1;
    const sentPercentTxn = await nano.sendPercent(secretKey, recipientAddress, sendPercentage);
    if (sentPercentTxn.hash) {
        console.log('Sent percentage transaction:', sentPercentTxn);
    }
}

// Execute the main function
main();

nanopay's People

Contributors

besoeasy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tylerpennexx

nanopay's Issues

typo in done1 and done2 console log

Currently:

    //recieve pending transactions
var done1 = await nano.fetchPending(secrateKey);

if (done1.hash) {
	console.log('fetched : ' + done.hash);
}

      // send nano to address
var done2 = await nano.send(secrateKey, nanoaddress, amount);

if (done2.hash) {
	console.log('sent : ' + done.hash);
}

should be:

//recieve pending transactions
var done1 = await nano.fetchPending(secrateKey);

if (done1.hash) {
console.log('fetched : ' + done1.hash);
}

        // send nano to address
var done2 = await nano.send(secrateKey, nanoaddress, amount);

if (done2.hash) {
console.log('sent : ' + done2.hash);
}

PoW pre rendering idea

Hi Besoeasy,
First of all I want to thank you for this piece of code, I have a blast playing with nano and code at the same time. It also helps that your code is very readable.

I created a function that allows you to create and store a new PoW at the start of the application and each time you spend the old PoW and need a new one. This saves some time for the end user because generating a PoW can take some time. It is not finished, and not perfect, but I do want to share it with you.

setTimeout(() => {
	generatePow(secrateKey);
}, 1000);

var pow = null;
async function generatePow(secretKey) {
	var address = await secretKeytoaddr(secretKey);
	var sddsf_address = await accountdig(address);
	var previous = sddsf_address.frontier;
	console.log("generating PoW")
	pow = await hybirdWork(previous);
	console.log("PoW ready");
}

async function send(secretKey, sendto, amount) {
	
        if(pow == null){
		console.log("PoW not ready yet")
		return;
	}

        ...

	generatePow(secretKey);

	return retr;
}

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.