Skip to content

Instantly share code, notes, and snippets.

@CaliosD
Created February 23, 2019 07:59
Show Gist options
  • Save CaliosD/ab78810e73f13975f9200fbf163507ed to your computer and use it in GitHub Desktop.
Save CaliosD/ab78810e73f13975f9200fbf163507ed to your computer and use it in GitHub Desktop.
Some snippets for self testing on local node of IOST blockchain. Feel free to use for testing, and feel free to star🌟if it's useful to you. 🚀
const IOST = require('iost')
const bs58 = require('bs58');
const config = require("./config.dev.json")
/* config.dev.json like this:
{
"rpcURL": "http://localhost:30001",
"privKey": "2yquS3ySrGWPEKywCPzX4RTJugqRh7kJSo5aehsLYPEWkUxBWA39oMrZ7ZxuM4fgyXYs2cPwh5n8aNNpH5x2VyK1"
}
*/
// init iost sdk
let iost = new IOST.IOST({ // will use default setting if not set
gasPrice: 100,
gasLimit: 2000000,
delay: 0,
}, new IOST.HTTPProvider(config.rpcURL));
// use RPC
const rpc = new IOST.RPC(new IOST.HTTPProvider(config.rpcURL));
iost.setRPC(rpc);
// init admin account
const account = new IOST.Account("admin");
const kp = new IOST.KeyPair(bs58.decode(config.privKey));
account.addKeyPair(kp, "active");
iost.setAccount(account);
const getContractStorage = async (contractId, key, field) => {
let result = await rpc.blockchain.getContractStorage(contractId, key, field, true);
return result["data"]
}
module.exports = {
getContractStorage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment