@drjiro/iost-client
v0.1.0
Published
iost JavaScript Client SDK
Readme
IOST client Library
import
import { IOST } from '@iost/client';or
const { IOST } = require('@iost/client');iost
create iost instance
const config = {
"host": "http://localhost:30001",
"chainId": 1020
};
const iost = new IOST(config);wallet
create wallet instance with local admin account
import { Wallet, Account, Ed25519, Bs58 } from '@iost/client';
const seckey = '2yquS3ySrGWPEKywCPzX4RTJugqRh7kJSo5aehsLYPEWkUxBWA39oMrZ7ZxuM4fgyXYs2cPwh5n8aNNpH5x2VyK1';
const wallet = new Wallet([
new Account('admin')
.addKeyPair('active', Ed25519.fromSecretKey(Bs58.decode(seckey)))
.addKeyPair('owner', Ed25519.fromSecretKey(Bs58.decode(seckey)))
]);
encrypt
console.log(wallet.toString('your-password'));decrypt
const wallet = Wallet.parse('encrypted-wallet-data', 'your-password');send transaction
Step.1 create empty transaction
const tx = iost.createTransaction({ gasLimit: 500000 });Step.2 add contract actions
import { OfficialContracts } from '@iost/client';
/** Skip Step 1 **/
// create official iost contract caller
const contracts = new OfficialContracts(tx);
// add actions
contracts.vote_producer.getVote('eversystem');Step.3 set transaction time
await iost.setServerTimeDiff();
tx.setTime(1000, 0, iost.serverTimeDiff);Step.4 add signatures
const account = wallet.accounts[0];
await iost.sign(wallet, tx, account, []);Step.5-1 send tx (event emitter)
// This example will listen irreversible transaction result
iost.send(tx, { times: 300, irreversible: true })
.once('pending', (res) => {
console.log('[pending]');
console.log(res);
})
.once('packed', (res) => {
console.log('[packed]');
console.log(res);
})
.once('irreversible', (res) => {
console.log('[irreversible]');
console.log(res);
})
.once('failed', (res) => {
console.log('[failed]');
console.log(res);
});Step.5-2 send tx (async function)
// This example will listen packed transaction result
const res = await iost.sendAsync(tx, {});
console.log(res);exec transaction
[WARNING] This api is additional option. You should check that the target iost node allows 'execTx' or not.
const res = await iost.exec(tx);
console.log(res);