The IRISnet JavaScript SDK allows browsers and Node.js clients to interact with IRISnet. Core functionality and examples
are in the test
folder.
- client - client that implements IRISnet transactions types, such as for transfers and staking,etc.
- crypto - core cryptographic functions.
- accounts - management of accounts and wallets, including seed and encrypted mnemonic generation, recover account by mnemonic or keystore, etc.
Install the package via npm.
npm install https://github.com/irisnet/irishub-sdk-js.git
interface ClientConfig {
node: string,//address of a rpc node on IRISnet
chainNetwork: consts.ChainNetwork; // IRISHUB = 0, Cosmos = 1, Akash = 2
chainId: string,
gas?: string,
fee?: {
denom: string;
amount: string;
}, //default fee for transactions
keyDAO: KeyDAO,//key manager for wallet, which must be implemented
bech32Prefix?: {
AccAddr: string,
AccPub: string,
ValAddr: string,
ValPub: string,
ConsAddr: string,
ConsPub: string,
},
rpcConfig?: AxiosRequestConfig// axios request config
}
First you should implement your KeyDAO like follows:
class KeyDAO {
/**
* save private key to client
* @param name for account you generated, which will be use to query private key and other account info
* @param wallet: {address: string,privateKey: string,publicKey: string,mnemonic: string}
* @throws error if save failed
*/
write(name, wallet):void {
localStorage.setItem(name, JSON.stringify(wallet));
}
/**
* save walet in client
* @param name
* @throws error if read failed
*/
read(name):wallet{
const wallet = localStorage.getItem(name);
if(wallet) {
return JSON.parse(wallet);
}
throw new Error(`no wallet was found`)
}
/**
* encrypt your private key before save to client
* @param private key
* @param password for encrypt private key
*/
encrypt?(privateKey, password): string {
return CryptoJS.AES.encrypt(msg, password).toString();
}
/**
* decrypto your private key with password
* @param encrypted private key
* @param password that can decrypto private key ecrypted
*/
decrypt?(encryptedPrivateKey, password): string {
const bytes = CryptoJS.AES.decrypt(encryptedPrivateKey, password);
const privateKey = bytes.toString(CryptoJS.enc.Utf8);
if (privateKey) {
return privateKey
} else {
throw new Error('can not decrypto the private key');
}
}
}
import {newClient as irisSdkClient} from 'irishub-sdk-js';
const client = irisSdkClient(ClientConfig)
.withKeyDAO(new KeyDAO())
.withRpcConfig({timeout: 15000});
The following selected examples demonstrate basic client usage.
- create account
const account: { address: string, mnemonic: string } = client.keys.add(`wallet name`, 'wallet password');
- recover account by mnemonic
const account: string = client.keys.recover(`wallet name`, 'wallet password', `mnemonic`);
- recover account by keystore
const account: string = client.keys.recover(`wallet name`, 'wallet password', `keystore`);
- transfer example
const res = await client.bank.send({
to:`iaa1eqvkfthtrr93g4p9qspp54w6dtjtrn27ar7rpw`,
amount:[{
denom:`uiris`,
amount:`1000000`
}],
baseTx:{
from:`wallet name`,
password:`wallet password`,
gas:50000,
fee:{
denom:`uiris`,
amount:`500000`
}
}
})
- newStdTx
- queryAccount
- queryAccounts
- queryParams
- send
- multiSend
- queryBalance
- queryAllBalances
- queryTotalSupply
- querySupplyOf
- queryDenomMetadata
- queryDenomsMetadata
- queryParams
- addLiquidity
- removeLiquidity
- swapOrder
- queryLiquidity
- setWithdrawAddr
- withdrawRewards
- withdrawValidatorCommission
- fundCommunityPool
- withdrawTokenizeShareRecordReward
- withdrawAllTokenizeShareRecordReward
- queryParams
- queryValidatorOutstandingRewards
- queryValidatorCommission
- queryValidatorSlashes
- queryDelegationRewards
- queryDelegationTotalRewards
- queryDelegatorValidators
- queryDelegatorWithdrawAddress
- queryCommunityPool
- queryTokenizeShareRecordReward
- stakeLp
- unStakeLp
- harvestReward
- queryFarmPools
- queryFarmPool
- queryFarmer
- queryParams
- queryProposal
- queryProposals
- queryVote
- queryVotes
- queryDeposit
- queryDeposits
- queryTally
- submitParameterChangeProposal
- submitPlainTextProposal
- submitCommunityTaxUsageProposal
- deposit
- vote
- voteWeighted
- createHTLC
- claimHTLC
- queryHTLC
- queryAssetSupply
- queryAssetSupplies
- queryParams
- transfer
- queryDenomTrace
- queryDenomTraces
- queryParams
- queryChannels
- transfer
- queryClassTrace
- queryClassTraces
- queryClassHash
- queryEscrowAddress
- queryParams
- add
- recover
- import
- importPrivateKey
- export
- exportPrivateKey
- delete
- show
- issueDenom
- mintNft
- editNft
- transferNft
- burnNft
- querySupply
- queryOwner
- queryCollection
- queryDenom
- queryDenoms
- queryNFT
- queryFeed
- queryFeeds
- queryFeedValue
- deserializeTx
- unpackMsg
- deserializeSignDoc
- deserializeTxRaw
- deserializeSigningInfo
- deserializePubkey
- queryRandom
- queryRequest
- request
- queryDefinition
- queryBinding
- queryBindings
- queryRequest
- queryRequests
- queryRequestsByReqCtx
- queryRequestContext
- queryResponse
- queryResponses
- queryFees
- defineService
- bindService
- updateServiceBinding
- disableServiceBinding
- enableServiceBinding
- invokeService
- setWithdrawAddress
- refundServiceDeposit
- startRequestContext
- pauseRequestContext
- killRequestContext
- updateRequestContext
- withdrawEarnedFees
- withdrawTax
- queryParams
- querySigningInfo
- unjail
- delegate
- undelegate
- redelegate
- tokenizeShares
- redeemTokensForShares
- transferTokenizeShareRecord
- disableTokenizeShares
- enableTokenizeShares
- validatorBond
- UnbondValidator
- queryDelegation
- queryDelegations
- queryUnbondingDelegation
- queryDelegatorUnbondingDelegations
- queryRedelegation
- queryDelegatorValidators
- queryDelegatorValidator
- queryHistoricalInfo
- queryValidatorDelegations
- queryValidatorUnbondingDelegations
- queryValidator
- queryValidators
- queryPool
- queryParams
- queryTokenizeShareRecordById
- queryTokenizeShareRecordByDenom
- queryTokenizeShareRecordsOwned
- queryAllTokenizeShareRecords
- queryLastTokenizeShareRecordId
- queryTotalTokenizeSharedAssets
- queryTotalLiquidStaked
- queryTokenizeShareLockInfo
- appendZero
- createValidator
- queryBlock
- queryBlockResult
- queryTx
- queryValidators
- searchTxs
- queryNetInfo
- queryGlobalAccountNumber
- issueToken
- editToken
- mintToken
- transferTokenOwner
- swapFeeToken
- SwapToERC20
- SwapFromERC20
- queryTokens
- queryToken
- queryFees
- queryParameters
- queryTotalBurn
- queryBalances
- buildTx
- newStdTxFromProtoTxModel
- buildAndSend
- broadcast
- sign
- sign_signDoc
- broadcastTxAsync
- broadcastTxSync
- broadcastTxCommit
- broadcastTx
- newTxResult
- createMsg