temtumjs-lib v1.0.1
Temtum JavaScript Library
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
Name | Type |
---|---|
type | String |
txIns | ArrayTxIn |
txOuts | ArrayTxOut |
timestamp | Number |
id | String |
Methods
addInput(txIn: TxIn)
Add transaction input into txIns array. TxIn properties:
Name | Type |
---|---|
address | String |
amount | Number |
txOutId | String |
txOutIndex | Number |
blockIndex | Number |
addOutput(txOut: TxOut)
Add transaction output into txOuts array. TxOut properties:
Name | Type |
---|---|
address | String |
amount | Number |
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.