0.0.2-beta.5 • Published 2 years ago
idesp.js v0.0.2-beta.5
Table of Contents
- IDEP.JS - Javascript library to facilitate and simplify interacting with the idep blockchain. - Table of Contents - Features - Installation - Quick Start Guide
- Using idep.js - Idep.js client - Wallet - Create new wallet - Retrieving wallet from storage - Wallet restoration - Query the account's balance - Create and send a simple transaction, that sends coins - Check tx status
- Possible queries and transactions - Auth src/x/auth - Bank src/x/bank - NFT src/x/nft - Appendix and FAQ
Features
- Works both in node.js and in browser environments.
- Written in Typescript.
- Wallet creation, persistence, restoration (from the mnemonic phrase or a private key). Can be used to create wallets for other blockchains.
- Querying the idep blockchain, sending transactions.
- Safe encryption, based on the native APIs (crypto in node, subtleCrypto in a browser).
- Uses protocol buffers.
Installation
yarn add idep.js
or
npm install idep.js
Quick Start Guide
If you are in a hurry, start here.
- Install idep.js with either yarn or npm.
- Create client's instance.
import {createNewClient} from 'idep.js';
const client = createNewClient(); // uses default configuration
- Create new wallet. Password is used to encrypt the private key. You will need it to make a transaction. Name is used for persistence.
const wallet = await client.wallet.createNew('encryptionPwd', 'walletName');
- After creating your wallet successfully, you can start making queries and transactions! Below^1 you can find a list with possible ones that you can make with the idep.js.
Using IDEP.js
IDEP.js client
To start, import and create the client.
import {createNewClient} from 'idep.js';
const client = createNewClient({
nodeUrl: 'http://159.89.84.111:26657',
chainId: 'SanfordNetwork',
fee: {
gas: '7000',
amount: [{ denom: 'idep', amount: '500' }],
},
}); // default config
Configuration can be omitted, in that case the default one is going to be used.
const client = createNewClient()
Wallet
After wallet is created, retrieved, or restored; it's stored on the client's instance. Private key is encrypted with provided password.
Create new wallet
const wallet = await client.wallet.createNew('encryptionPwd', 'walletName');
const {mnemonic, publicKey, address} = wallet;
This is the only time when mnemonic phrase can be accessed. Make sure to store it securely. Naming a wallet is optional (it defaults to the wallet's address).
Retrieving wallet from storage
const wallet = await client.wallet.retrieveSavedWallet('name');
const {publicKey, address} = wallet;
Wallet restoration
With a mnemonic phrase:
const mnemonic = 'power thing inmate obscure rubber frequent grit hair below museum notable reopen spoon prize family caught axis host';
const wallet = await client.wallet.restoreWithSeed(mnemonic, 'password');
With private key:
const privateKey = 'hexEncodedPrivateKeyString';
const wallet = await client.wallet.restoreWithPrivateKey(privateKey, 'password')
Query the account's balance
const address = 'idep126dfeu0d6awmdjy29e4f04eg0g3kvcpz9dazru';
const denom = 'idep'
const response = await client.bank.checkBalance(address, denom);
console.log(response); // {balance: {amount: '10000000150', denom: 'idep'}}
Create and send a simple transaction, that sends coins
const txResult = await client.bank.msgSend({
recipient: 'idep126dfeu0d6awmdjy29e4f04eg0g3kvcpz9dazru',
amount: [{
denom: 'idep',
amount: '25'
}],
}, {
from: client.wallet.address, // optional
pub_key: client.wallet.publicKey, // optional
fee: {
gas: '7000',
amount: [{
denom: 'idep',
amount: '700'
}],
}, // optional
simulate: false, // optional
password: 'password', // needed to decrypt a private key, which is needed to sign the tx
});
console.log(txResult); // 'Tx hash 26919CA117C5D5240AF144D6A7765AE31372D9E167CB596A46210AC986F28C03'
You also can simulate the transaction beforehand so you get required gas estimate. To do it, simply change the simulate flag to true.
Check tx status
const txHash = '26919CA117C5D5240AF144D6A7765AE31372D9E167CB596A46210AC986F28C03';
const status = await client.rpc.checkTx(txHash);
^1:
Possible queries and transactions
Auth src/x/auth
- checkAccountInfo (queryAccount)
- checkAuthParams (queryParams)
Bank src/x/bank
- checkBalance (queryBalance)
- checkALlBalances (queryAllBalances)
- checkSupply (querySupplyOf)
- checkParams (queryParams)
- checkBalance (queryAllBalances)
- checkALlBalances (queryAllBalances)
- msgSend
- msgMultiSend
NFT src/x/nft
- checkSupply (querySupply)
- checkOwner (queryOwner)
- checkCollection (queryCollection)
- checkDenom (queryDenom)
- checkMultipleDenoms (queryDenoms)
- checkNft (queryNFT)
- msgIssueDenom
- msgMintNFT
- msgEditNFT
- msgTransferNFT
- msgBurnNFT
Appendix and FAQ
❓ More Questions?
Chat with the team on the IDEP Discord server IDEP.js channel!
Something doesn't work as expected? Open a new issue!