This package aims to provide with an easy-to-use JS helping developers to communicate with the Noah blockchain through its API.
This package should be an aid to any developer working on JS applications with the Noah blockchain.
Please note that this SDK is under active development and is subject to change.
It is complemented by the following packages:
- noahjs-wallet take care of NOAH39 mnemonic phrase, private key and address
- noahjs-tx create, manipulate and sign transactions
- noahjs-util utility functions
Install
npm install noah-sdk-js
or from browser
Usage
Post transaction full example
; const noahSDK = apiType: 'node' baseURL: 'https://noah-node-1.testnet.minter.network';const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' nonce: 1 chainId: 1 address: 'Mx7633980c000139dd3bd24a3f54e06474fa941e16' amount: 10 coinSymbol: 'MNT' feeCoinSymbol: 'ASD' gasPrice: 1 message: 'custom message'; noahSDK ;
Initialization
Create noahSDK
instance from Noah
constructor
Noah
accept axios config as params and return axios instance
One extra field of options object is apiType
, which is one of 'gate'
or 'node'
. It is used to determine what type of API to use.
// specify gate urlconst noahGate = apiType: 'gate' baseURL: 'https://gate.minter.network';// specify node urlconst noahNode = apiType: 'node' baseURL: 'https://noah-node-1.testnet.minter.network';
Noah
constructor has the following options:
apiType
: 'gate' or 'node'baseURL
: API urlchainId
: default chain ID, used if no chainId specified in the tx params
noahSDK
instance has the following methods:
- postTx
- postSignedTx
- getNonce
- estimateCoinSell
- estimateCoinBuy
- estimateTxCommission
- issueCheck
- decodeCheck
.postTx()
Post new transaction to the blockchain
Accept tx params object and make asynchronous request to the blockchain API.
txParams.nonce
- optional, if no nonce given, it will be requested by getNonce
automatically.
txParams.gasPrice
- 1 by default, fee multiplier, should be equal or greater than current mempool's min gas price.
gasRetryLimit
- count of repeating request, 2 by default. If first request fails because of low gas, it will be repeated with updated gasPrice
Returns promise that resolves with sent transaction hash.
/** * @typedef * @property * @property * @property * @property * @property * @property * @property * @property */ /*** @param* @param* @return */noahSDK
.postSignedTx()
Post new transaction to the blockchain Accept signed tx string or Buffer and make asynchronous request to the blockchain API. Returns promise that resolves with sent transaction hash.
/*** @param* @return */noahSDK
.getNonce()
Get nonce for the new transaction from given address. Accept address string and make asynchronous request to the blockchain API. Returns promise that resolves with nonce for new tx (current address tx count + 1).
noahSDK
.estimateCoinSell()
Estimate how much coins you will get for selling some other coins.
noahSDK
.estimateCoinBuy()
Estimate how much coins you will pay for buying some other coins.
noahSDK
.estimateTxCommission()
Estimate transaction fee. Useful for transactions with gasCoin
different from base coin NOAH (or MNT).
Accept string with raw signed tx.
Resolves with commission value.
noahSDK
.issueCheck()
Noah Checks are issued offline and do not exist in blockchain before “cashing”.
// Since issuing checks is offline, you can use it standalone without instantiating SDK;const check = ;console;// => 'Mcf8a002843b9ac9ff8a4d4e5400000000000000888ac7230489e80000b841ed4e21035ad4d56901422c19e7fc867a63dcab709d6d0dcc0b6333cb7365d187519e1291bbc002189e7030dedfbbc4feb733da73f9409de4f01365dd3f5f4927011ca0507210c64b3aeb7c81a2db06204b935814c28482175dee756b1f05414d18e594a06173c7c8ee51ad76e9704a39ffc5c0ab11514d8b68efcbc8df1db194d9e296ee' // This method also available on the SDK instanceconst check = noahSDK;
.decodeCheck()
Decode raw check
// Since issuing checks is offline, you can use it standalone without instantiating SDK;const check = ;console;// =>// {// nonce: '1',// chainId: 1,// coin: 'MNT',// value: '10',// dueBlock: 999999,// } // This method also available on the SDK instanceconst check = noahSDK;
Tx params constructors
Get params object from constructor and pass it to postTx
method to post transaction to the blockchain
Send
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 address: 'Mx7633980c000139dd3bd24a3f54e06474fa941e16' amount: 10 coinSymbol: 'MNT' feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Multisend
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 list: value: 10 coin: 'MNT' to: 'Mx7633980c000139dd3bd24a3f54e06474fa941e16' value: 2 coin: 'MNT' to: 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99' feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Sell
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 coinFrom: 'MNT' coinTo: 'BELTCOIN' sellAmount: 10 feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Sell All
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 coinFrom: 'MNT' coinTo: 'BELTCOIN' feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Buy
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 coinFrom: 'MNT' coinTo: 'BELTCOIN' buyAmount: 10 feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Create Coin
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 coinName: 'My Coin' coinSymbol: 'MYCOIN' initialAmount: 5 crr: 10 initialReserve: 20 feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Declare Candidacy
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 address: 'Mx7633980c000139dd3bd24a3f54e06474fa941e16' publicKey: 'Mpf9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a3' commission: 10 coinSymbol: 'MNT' stake: 100 feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Edit Candidate
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 publicKey: 'Mpf9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a3' rewardAddress: 'Mx7633980c000139dd3bd24a3f54e06474fa941e16' ownerAddress: 'Mx7633980c000139dd3bd24a3f54e06474fa941e16' feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Delegate
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 publicKey: 'Mpf9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a3' coinSymbol: 'MNT' stake: 100 feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Unbond
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 publicKey: 'Mpf9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a3' coinSymbol: 'MNT' stake: 100 feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Set Candidate On
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 publicKey: 'Mpf9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a3' feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Set Candidate Off
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 publicKey: 'Mpf9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a3' feeCoinSymbol: 'ASD' message: 'custom message'; noahSDK;
Redeem Check
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 check: 'Mcf8a002843b9ac9ff8a4d4e5400000000000000888ac7230489e80000b841ed4e21035ad4d56901422c19e7fc867a63dcab709d6d0dcc0b6333cb7365d187519e1291bbc002189e7030dedfbbc4feb733da73f9409de4f01365dd3f5f4927011ca0507210c64b3aeb7c81a2db06204b935814c28482175dee756b1f05414d18e594a06173c7c8ee51ad76e9704a39ffc5c0ab11514d8b68efcbc8df1db194d9e296ee' password: '123' feeCoinSymbol: 'MNT'; noahSDK;
Create Multisig
;const txParams = privateKey: '5fa3a8b186f6cc2d748ee2d8c0eb7a905a7b73de0f2c34c5e7857c3b46f187da' chainId: 1 addresses: 'Mx7633980c000139dd3bd24a3f54e06474fa941e00' 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99' weights: 40 80 threshold: 100 feeCoinSymbol: 'MNT'; noahSDK;
Prepare Signed Transaction
Used under the hood of PostTx, accepts txParams
object as argument
;const tx = ;console; // get actual nonce firstnoahSDK ;
License
MIT License