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

@bandonli/codexjs

v1.0.3

Published

General purpose library for the EOS blockchain.

Downloads

2

Readme

codex API

安装 codexjs

npm install codexjs
//or
yarn add codexjs

使用

import Codex from 'codexjs'

全局配置

参数:

httpEndpoint: 节点rpc接口
chainId: 节点chainId 可以通过 get_info 获取


const node_config = {
  httpEndpoint: node_url,
  chainId
}

getAbi

通过合约账户获取ABI, ABI包含当前合约的所有可执行函数和函数需要的配置 参数:

contranct_name: 合约账户

使用

Codex({
    httpEndpoint
})
.getAbi('codex')
.then(abi_data => {
  console.log(abi_data);
  console.log(abi_data.actions); //所有ABI的可执行的方法
});

getInfo

获取节点最新信息 参数:

{}

使用:

const test_get_info = async () => {
  let info = await Codex(node_config).getInfo({}); //api getInfo, {}为必传参数
  console.log(`node info is ${JSON.stringify(info)}`);
}
test_get_info();

getBblock

根据区块号或区块id获取区块详细信息 参数:

block_num_or_id

使用:

const test_get_block = async (block_num_or_id = 10) => {
  let block_info = await Codex(node_config).getBlock(block_num_or_id); //api getBlock
  console.log(`block info is ${JSON.stringify(block_info)}`);
}
test_get_block();

getAccount

获取内存,网络,CPU,权限等账户信息 参数:

account_name

使用:

const test_get_account = async (account_name = 'codex') => {
  let info = await Codex(node_config).getAccount(account_name); 
  console.log(`account info is ${JSON.stringify(info)}`);
}
test_get_account();

getTableRows

合约账户下表查询 参数:

code: 合约账户名
table: 合约账户下的表名
scope: 查询条件
limit: 查询最大长度

查询用户资产表

使用:

const test_get_available = async (account_name = 'testc') => {
  let 参数 = { 
    scope: account_name, //查询条件
    code: 'codex.token', //合约账户
    table: 'accounts', //表名
    limit: 10000,
    json: true,
  }
  let account_info = await Codex(node_config).getTableRows(参数); // api getTableRows
  console.log(account_info)
}
test_get_available();

查询所有超级节点

使用:

const test_get_bps_table = async (account_name = 'testc') => {
  let 参数 = {
      scope: 'codex',
      code: 'codex',
      table: 'bps',
      json: true,
      limit: 1000 
  }
  let account_info = await Codex(node_config).getTableRows(参数);
  console.log(account_info)
}
test_get_bps_table();

获取出块节点

使用:

const test_get_block_productor = async () => {
  let codex_token = await Codex(node_config);
  let node_info = await codex_token.getInfo({});

  let head_block_num = node_info.head_block_num; //节点最新区块编号
  let head_block_info = codex_token.getBlock(head_block_num); //最新区块详细信息
  let schedule_version = head_block_info.schedule_version; //区块所在届
  //查询当届出块节点表数据
  let 参数 = {
      scope: 'codex',
      code: 'codex',
      table: 'schedules',
      table_key: '0',
      json: 'true',
      limit: 1000,
  }
  let supber_bps = await Codex(node_config).getTableRows(参数);
  console.log(supber_bps)
}
test_get_block_productor();

抵押

抵押将可用余额向抵押池添加主币; 抵押用户:投票,租赁内存将使用抵押池里的主币,所以投票,租赁内存前确保抵押池必须有主币。 合约账户: ‘codex’ 参数:

voer: 抵押给哪个账户
stake: 抵押数量


const test_freeze = async (your_private_key, voter, freeze_ammount) => {
  let private_config = Object.assign({keyProvider: your_private_key}, node_config);
  let codex_token = await Codex(private_config).contract('codex');
  let res = await codex_token.freeze(voter, freeze_ammount);
  console.log(res);
}

test_freeze( keyProvider,'testc', '11112.0000 CDX')

投票挖矿

投票给超级节点,若是所投节点为超级节点,将分享节点的出块奖励 合约账户: codex 参数:

voter: 为哪个账户投票
bpname: 所投节点的名称
stake: 投票数量

转账

合约账户: codex.token 参数:

from: 转出账户
to: 转入账户
quantity: 转账数量
memo: 转账备注信息,非必填,没有使用空字符串

领取投票分红

合约账户: codex, 参数:

bpname: 从哪个节点领取分红
receiver: 领取分红分配到哪个账户

使用示例:

const test_claim_vote_share = async (your_private_key, voter, bpname) => {
  let private_config = Object.assign({keyProvider: your_private_key}, node_config);
  let codex_token = await Codex(private_config);

  // 领取分红前,需要调用 opencast 打开铸币池
  await codex_token.transaction(['codex', 'codex.token'], contracts => {
      contracts.codex_token.opencast(voter);
      contracts.codex.claimvote(bpname, voter, {'actor': voter, 'permission': 'active'}); 
    })

}

test_claim_vote_share(keyProvider, your_account_name, the_block_node_you_voted);

领取挖矿分红

合约账户: relay.token, codex.token 参数:

chain: 代币所在链的名称
quantity:  领取分红数量, 当前数量没有作用,主要识别代币符号, 可填 “0.0000 token_symbol”receiver: 领取分红的人




const test_claim_token_share = async (your_private_key, chain, quantity = '0.0000 ADD', receiver) => {
  let private_config = Object.assign({keyProvider: your_private_key}, node_config);
  let codex_token = await Codex(private_config);

  // 领取分红前,需要调用 opencast 打开铸币池
  await codex_token.transaction(['relay.token', 'codex.token'], contracts => {
      contracts.codex_token.opencast(receiver);
      contracts.relay_token.claim( chain, quantity, receiver, {'actor': receiver, 'permission': 'active'});
  })

}

test_claim_token_share(keyProvider, 'eosforce', '0.0000 ADD', 'testc');

跨链充值

跨链提现

跨链资产转账

合约名称: relay.token 参数:

from: 转出账户
to: 转入账户
chain: 链名称
amount: 转账数量
memo: 备注,可不填,不填输入空字符串

使用:

Codex({keyProvider, httpEndpoint, chainId})
.contract('relay.token')
.then(async token => {
  let res = token.transfer(from, to, chain, amount, memo);
  console.log( res );
})
.catch(err => {
  throw err;
});

计算挖矿分红

计算投票分红

更改账户权限

合约账户:codex 参数:

name: 修改权限账户名
perm_name: 需要修改的权限的名称
parent_perm_name: 需要修改的权限的父权限, 若是acitve, 父权限为owner. 若是owner, 父权限为’’
public_key: 将账户下的权限转移到当前公钥

使用示例:

Codex({keyProvider, httpEndpoint, chainId}).transaction(contract_account, tr => {
    tr.updateauth(name, 'active', 'owner', active_public_key, auth); //修改active 权限公钥
    tr.updateauth(name, 'owner', '', owner_public_key, auth);//修改owner 权限公钥
  })

获取交易记录

参数:

account_name: 查询当前账户的交易记录
pos: 从哪条记录开始查询, 若是需要从最近开始查询,使用-1,offset 设为 负数, 若要查询更多,获取查询记录最后一条的 account_action_seq 作为pos
offset: 查询的条怒


Codex({}).getActions({
      account_name: accountName, 
      pos: pos, 
      offset: offset
})
.then(data => {
  console.log(data);
});

私钥生成

const { ecc, Fcbuffer } = Codex.modules;
const randomKey = async () => {
    return await ecc.randomKey();
};

公钥获取

const privateToPublic = (private_key, symbol = 'EOS') => {
    let public_key = ecc.privateToPublic(private_key);
    return public_key.replace(/^EOS/, symbol);
}

获取公钥下账户

参数:

public_key: 公钥


Codex({httpEndpoint}).getKeyAccounts(public_key).then(data => {
    console.log(data);
})