1.0.1 • Published 5 years ago

temtumjs-lib v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

Temtum JavaScript Library

Covered with

NPM

A JavaScript Temtum library.

About

Temtum is a new, lightweight, peer-to-peer cryptocurrency where anyone can support the Temporal blockchain network, creating a new world of financial freedom away from centralised institutions.

This library will help you to make various operations in Temtum network using simple interface.

How to install

npm install temtumjs-lib --save

How to use

If you want to use this library on Node.js:

const temtumjs = require('temtumjs-lib');

Usage example

const Transaction = require('temtumjs-lib').Transaction;
const Wallet = require('temtumjs-lib').Wallet;

// Your Temtum wallet keys. If you don't have a key pair, you can generate one using Wallet.generateKeyPair method
const PUBLIC_KEY = 'your_temtum_public_key';
const PRIVATE_KEY = 'your_temtum_private_key';

// Create Transaction instance
const transaction = new Transaction();

// Get unspent outputs of your wallet. If you already have any, you can add it using Transaction.addInput method
Wallet.getUnspent(PUBLIC_KEY).then((response) => {
  // Use unspent outputs as inputs for the new transaction
  transaction.txIns = response.unspentTxOuts;
  // Add transaction output
  transaction.addOutput('output_address', 10);
  // Add unused inputs as transaction output back to your address
  transaction.addUnspentInputsToOutput();
  // Sign the transaction using your private key
  transaction.sign(PRIVATE_KEY);

  // Send the transaction to Temtum node
  transaction.send().then(() => {
    console.log('You have successfully sent a transaction!');
  });
});

API doc

Transaction

Properties

NameType
typeString
txInsArrayTxIn
txOutsArrayTxOut
timestampNumber
idString

Methods

addInput(txIn: TxIn)

Add transaction input into txIns array. TxIn properties:

NameType
addressString
amountNumber
txOutIdString
txOutIndexNumber
blockIndexNumber

addOutput(txOut: TxOut)

Add transaction output into txOuts array. TxOut properties:

NameType
addressString
amountNumber

calculateTotalInputsAmount() -> Number

Calculate total amount of TEMs in transaction inputs.

calculateTotalOutputsAmount() -> Number

Calculate total amount of TEMs in transaction outputs.

addUnspentInputsToOutput()

Calculate total amount of TEMs in transaction inputs and, if it's greater than total amount of TEMs in transaction outputs, create new transaction output with unspent inputs amount and the address of inputs.

sign(privateKey: String)

Generate transaction id based on transaction properties and add signatures to transaction inputs.

getHexString() -> String

Return transaction as a hex string.

send() -> Promise(null)

Send transaction to Temtum node.

Wallet

Methods

(static) getUnspent(address: String) -> Promise({ unspentTxOuts: ArrayTxIn })

Get unspent outputs for a specific address.

(static) sendTransaction(from: String, to: String, amount: Number, privateKey: String) -> Promise({ transaction: Object })

Send new transaction to Temtum node using specific properties.

(static) generateKeyPair() -> Promise({ privateKey: String, address: String })

Generate new public and private keys pair.