npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@crichain/kit.js

v2022.1.3

Published

FClink Chain JavaScript API & SDK

Downloads

3

Readme

@crichain/kit.js


Install

$ npm install @crichain/kit.js

Super simple to use

Setting up the network,@crichain/kit.js support network has testnet and prodnet

const brew=require('@crichain/kit.js');
var rp = require('request-promise')
//set prodnet network
brew.config.server_base='http://rc.domain.com/fbs';
brew.config.net_type='prodnet'
brew.config.rpc_provider = rp;

Create keystore.json、keypair

const brew=require('@crichain/kit.js');
const fs=require('fs');
var kp = brew.KeyPair.genRandomKey();
/**
* create keystore
* @param {*} kp
* @param {*} password
*/
var json = brew.keystore.exportJSON(kp,"000000");
let fd = fs.openSync('keystore.json', 'w+');
fs.writeSync(fd,JSON.stringify(json));
console.log('keypair',kp);

Get balance and nonce

const brew=require('@crichain/kit.js');
/**
* get balance and nonce
* @param {*} address
* @result {
        "retCode": 1,
        "address": "0x46f1f188bca9c555464ab41daecffaa0405f177c",
        "nonce": 0,//nonce
        "balance": "0x21e19e0c9bab2400000",//16进制余额
        "status": 0
    } 
*/
brew.rpc.getBalance('8f3aa4f0f35ff81ba487f91f6b980c0ba2562245').then(function(result){
    console.log(result.account.balance)
    console.log(result.account.nonce)
})

Get block info by hash

const brew=require('@crichain/kit.js');
/**
* get block info by hash
* @param {*} blockhash
*/
brew.rpc.getBlockByHash('03a15d84e6e29d2affab1ddc680f0aefc20586bd73ea3d81dcf6505924cfb86c').then(function(result){
    console.log(result)
})

Get block info by height

const brew=require('@crichain/kit.js');
/**
* get block info by height
* @param {*} height
*/
brew.rpc.getBlockByNumber('1518059').then(function(result){
    console.log(result)
})

Get the current height of the BREW blockchain

const brew=require('@crichain/kit.js');
brew.rpc.getBlockByMax().then(function(result){
    console.log(result)
})

Get transaction information through transaction hash

const brew=require('@crichain/kit.js');
/**
* get transaction information
* @param {*} transactionhash
*/
brew.rpc.getTransaction('f9bea09140e8e2eb2956976c3373418e2a935d821732d86bce33117d17314088').then(function(result){
    console.log(result)
})

Send transfer,support balance transfer,token transfer, crypto token transfer 。

const brew=require('@crichain/kit.js');
/**
* get keystore by prikey
* @param {*} prikey
*/
var kp = brew.KeyPair.genFromPrikey(
  '89611e9ed751b2bb0f2a84d1b364bd6ef97a512a7ad0b1b50241168ff3add985')
  
/**
* transfer
* @param {*} from {"keypair":{"hexAddress":"","privateKey":"",nonce:10}}
* @param {*} exdata "hexstring"
* @param {*} args [{"address":"066c03fcc3048863f72b051530e5a212fb9233f6","amount":""}]
* @result {*}
 *  {
 *      "retCode": 1, //1=成功 0=失败
 *      "hash": "70d994369495f2139102a8391e463418d0f6d62e4a2e1444949f3eba2e1ebf74b7"//交易hash
 *  }
*/
kp.nonce=10;
//remove prefix
kp.hexAddress=brew.rpc.removePrefix(kp.hexAddress);
var from={keypair:kp};
var args=[{"address":brew.rpc.removePrefix("066c03fcc3048863f72b051530e5a212fb9233f6"),"amount":1}]
var exdata=""
brew.rpc.transfer(from,extdata,args).then(function(result){
    console.log(result)
}).catch(function(error){
    console.log(error);
})

sign transfer

/**
 * sign transfer normal
 * @param {*} from {"keypair":{"address":"","privateKey":"",nonce:10}}
 * @param {*} exdata
 * @param {*} args [{"address":"066c03fcc3048863f72b051530e5a212fb9233f6","amount":""}]
 */
//only get sign
var sign = brew.rpc.signTransfer(from,extdata,args);

Create a token transaction

/**
* create token
* @param {*} from {"keypair":{"hexAddress":"","privateKey":"", "nonce": 0}}
* @param {*} exdata "hexstring"
* @param {*} args {"tos":["",""], "values":["",""],"name":"","symbol":"","decimals":18}
* @result {*}
 *  {
 *      "retCode": 1, //1=成功 0=失败
 *      "hash": "70d994369495f2139102a8391e463418d0f6d62e4a2e1444949f3eba2e1ebf74b7"//交易hash
 *  }
*/
brew.rpc.createToken(from,exdata args).then(function(result){
    console.log(result)
}).catch(function(error){
    console.log(error);
})

sign create token

/**
* create token
* @param {*} from {"keypair":{"hexAddress":"","privateKey":"", "nonce": 0}}
* @param {*} exdata "hexstring"
* @param {*} args {"tos":["",""], "values":["",""],"name":"","symbol":"","decimals":18} 
* @result {"tx":tx}
*/
//only get sign
var sign = brew.rpc.signCreateToken(from,extdata,args);

Transfer token transaction

/**
 * transfer token 
 * @param {*} from {"keypair":{"hexAddress":"","privateKey":"",nonce:10}}
 * @param {*} token
 * @param {*} args {"tos":["",""], "values":["",""]} 
 * @result {*}
 *  {
 *      "retCode": 1, //1=成功 0=失败
 *      "hash": "70d994369495f2139102a8391e463418d0f6d62e4a2e1444949f3eba2e1ebf74b7"//交易hash
 *  }
 */
brew.rpc.transferToken(from,token,args).then(function(result){
    console.log(result)
}).catch(function(error){
    console.log(error);
})

sign transfer token

/**
 * transfer token 
 * @param {*} from {"keypair":{"hexAddress":"","privateKey":"",nonce:10}}
 * @param {*} token
 * @param {*} args {"tos":["",""], "values":["",""]} 
 * @result {"tx":tx}
 */
var sign = brew.rpc.signTransferToken(from,extdata,args);

Create contract

/**
* create contract
* @param {*} from {"keypair":{"hexAddress":"","privateKey":"",nonce:10}}
* @param {*} exdata "hexstring"
* @param {*} args {"data":"hexstring"}
* @result {*} 
 *  {
 *      "retCode": 1, //1=成功 0=失败
 *      "hash": "70d994369495f2139102a8391e463418d0f6d62e4a2e1444949f3eba2e1ebf74b7"//交易hash
 *      "contractHash":""//合约地址 ,其他交易无此参数
 *  }
*/
brew.rpc.createContract(from,exdata,args).then(function(result){
    console.log(result)
}).catch(function(error){
    console.log(error);
})

sign Create contract

/**
* create contract
* @param {*} from {"keypair":{"hexAddress":"","privateKey":"",nonce:10}}
* @param {*} exdata "hexstring"
* @param {*} args {"data":"hexstring"}
* @result {"tx":tx}
*/
var sign = brew.rpc.signCreateContract(from,extdata,args);

Call contract

/**
 * call contract
 * @param {*} from 
 * @param {*} exdata
 * @param {*} args {"contract":"", "data":"hexstring", "amount":""}
 * @result {*}
 *  {
 *      "retCode": 1, //1=成功 0=失败
 *      "hash": "70d994369495f2139102a8391e463418d0f6d62e4a2e1444949f3eba2e1ebf74b7"//交易hash
 *  }
*/

brew.rpc.callContract(from,exdata,args).then(function(result){
    console.log(result)
}).catch(function(error){
    console.log(error);
})

sign Call contract

/**
 * call contract
 * @param {*} from 
 * @param {*} exdata
 * @param {*} args {"contract":"", "data":"hexstring", "amount":""}
 * @result {"tx":tx}
*/
var sign = brew.rpc.signCallContract(from,extdata,args);

License

MIT