1.0.3 • Published 1 year ago

newrl-js v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

newrl-js v 1.0.3

JS wrapper functions for interacting with the Newrl blockchain.

Requirements

  • Node JS (>=14.0.0)
  • npm (Node JS package manager)

Installation

Add newrl-js to your project requirements and/or run the installation with:

npm i newrl-js

Usage

Node JS

const newrl = require("newrl-js");

Initialise a node connection

A node address along with port can be given to initialise a new node connection. If no address is provided, the default newrl foundation node at address http://newrl.net:8090 will be used.

const node = new newrl.Node("http://3.6.236.206:8090/");

Off chain operations

Get file hash

Certain Newrl operations use document hashes for verification purpose. A file hash can be obtained with the below command.

ParameterTypeDescription
filestringRequired. file path

Example

const hash = await newrl.getFileHash("/home/user/file.txt");

Generate new wallet

A wallet address generation can be done off-chain. The result is a dictionary containing public, private and address of the new wallet. A wallet once generated should be added to the chain to make it available for use.

Example

const testWallet = new newrl.Wallet();

const wallet = await testWallet.getWalletAddress();

Sign transaction

A transaction need to be signed with the applicable wallet for addition to chain.

ParameterTypeDescription
wallet_dataobjectRequired. {JSON} wallet
transaction_dataobjectRequired. {JSON} transaction

Example

const signedWallet = await newrl.signTransaction(wallet, walletAddTransaction);

On chain operations

Add wallet to chain

A wallet address once genearated need to be signed and then added to the chain.

ParameterTypeDescription
custodian_addressstringRequired. Address of the custodian
jurisdictionstringRequired. Jurisdiction of the owner
public_keystringRequired. Public key of the owner
ownertype ?= "1"string{Optional} Type of owner
kyc_docs ?= []array{Optional} kyc documents of the owner
specific_data ?= {}object{Optional} Specific data of the owner

Example

let walletAddTransaction = await node.addWallet(
  wallet["address"],
  "910",
  wallet["publicKey"]
);

Add token to chain

A token can be created, signed and then validated to add to the chain.

ParameterTypeDescription
token_namestringRequired. Name of the token
token_typestringRequired. Type of the token
first_ownerstringRequired. First owner of the token
custodianstringRequired. Custodian of the token
legal_doc_hashstringRequired. Hash of the legal document
amount_creatednumberRequired. Amount of the token created
value_creatednumberRequired. Value of the token created
disallowed_regions ?= []array{Optional}. Disallowed regions of the token
token_attributes ?= {}object{Optional}. Attributes of the token
is_smart_contract_token ?= falseboolean{Optional}. Smart contract token

Example

const tokenDetails = await node.addToken(
  "my_new_token",
  "1",
  "0x16031ef543619a8569f0d7c3e73feb66114bf6a0",
  "0x16031ef543619a8569f0d7c3e73feb66114bf6a0",
  "fhdkfhldkhf",
  10000,
  10000
);

Add transfer

A transfer can be created between two wallets either unilaterally or bilaterally depending on the transfer type.

ParameterTypeDescription
asset1_codenumberRequired. Code of the asset1
asset2_codenumberRequired. Code of the asset2
wallet1_addressstringRequired. Address of the wallet1
wallet2_addressstringRequired. Address of the wallet2
asset1_qtynumberRequired. Quantity of the asset1
asset2_qtynumberRequired. Quantity of the asset2
transfer_typenumberRequired. Type of the transfer

Example

const transferTransaction = await node.addTransfer(
  9,
  10,
  "0x16031ef543619a8569f0d7c3e73feb66114bf6a0",
  "0x16031ef543619a8569f0d7c3e73feb66114bf6a0",
  10,
  10,
  4
);

Get balance

The balance of a given token in a wallet, across wallets or all tokens in a wallet can be obtained with get balance function.

ParameterTypeDescription
balance_typestringRequired. Balance Type
wallet_addressstringRequired. Wallet Address
token_codenumberRequired. Token Code

Example

const balance = await node.getBalance(
  "TOKEN_IN_WALLET",
  "0xc29193dbab0fe018d878e258c...",
  9
);

Test

Type the following command for testing

  npm test
1.0.2

2 years ago

1.0.3

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.0

2 years ago