codex API
Install
npm install cdxjs //oryarn add cdxjs
Usage
Config
parameters:
- httpEndPoint [string] codex chain rpc base host
- chainId [string] the id of codex chain, you can get by get_info
- keyProvider
Example:
const node_config = httpEndpoint: node_url chainId keyProvider
getAbi
ABI instruction all the methods that in contract.
parameters:
- contract_name [string]
Example:
const test_get_abi = async { let abi_content = await ; console;};
getInfo
get the chain info
parameters:
- empty_dict [Object] the empy object is neccessary.
Example:
const test_get_info = async { let info = await ; //api getInfo, `{}` is required console;};
getBblock
get block info with block num or block id
参数:
- block_num_or_id [string]
Example:
const test_get_block = async { let block_info = await ; //api getBlock console; } ;
getAccount
cpu, net, ram, public key can be goted by this api
parameters:
- account_name [string]
Example:
const test_get_account = async { let info = await ; console;};
getTableRows
query contract table
参数:
- code [string] the account of contract
- table [string] table name
- scope [string] query condition
- limit [number] the max rows you want
query an account's token
parameters:
scope: account_name // the account you want query code: 'codex.token' table: 'accounts' limit: 10000 json: true
Example:
const test_get_available = async { let params = scope: account_name code: 'codex.token' table: 'accounts' limit: 10000 json: true let account_info = await ; // api getTableRows console};
query blcok producers
parammeters:
scope: 'codex' code: 'codex' table: 'bps' json: true limit: 1000
Example:
const test_get_bps_table = async { let params = scope: 'codex' code: 'codex' table: 'bps' json: true limit: 1000 let account_info = await ; console};
query the producers which pack block data
Example:
const test_get_block_productor = async { let codex_token = await ; let node_info = await codex_token; let head_block_num = node_infohead_block_num; //block_num_or_id let head_block_info = await codex_token; //the latest block info let schedule_version = head_block_infoschedule_version; //the version let 参数 = scope: 'codex' code: 'codex' table: 'schedules' table_key: '0' json: 'true' limit: 1000 let supber_bps = await ; console} ;
抵押
抵押将可用余额中的代币添加到抵押池; 投票,租赁内存将使用抵押池里的主币,所以投票或租赁内存前确保抵押池必须有主币。
合约账户: ‘codex’
函数: freeze
参数:
voer: 抵押给哪个账户 stake: 抵押数量
使用示例:
const test_freeze = async { let private_config = Object; let codex_token = await ; let res = await codex_token; console;}
投票挖矿
投票给超级节点,若是所投节点为超级节点,将分享节点的出块奖励
合约账户: codex
函数: vote
参数:
voter: 为哪个账户投票 bpname: 所投节点的名称 stake: 投票数量
使用示例:
// keyProvider 为私钥const test_vote = async { let token = await ; let res = await token; console;};
内存租赁
投票给出块节点,将增加内存
合约账户: codex
函数: vote4ram
参数:
voter: 租赁账户 bpname: 节点名称 stake:
使用示例:
const test_vote4ram = async { let token = await ; let data = await token; console;};
转账
合约账户: codex.token
函数: transfer
参数:
from: 转出账户 to: 转入账户 quantity: 转账数量 memo: 转账备注信息,非必填,没有使用空字符串
使用示例:
const test_transfer = async { let token = await ; let res = await token; console;};
领取投票分红
合约账户: codex
参数:
bpname: 从哪个节点领取分红 receiver: 领取分红分配到哪个账户
::: 注意 领取投票分红必须在同一个块opencast :::
使用示例:
const test_claim_vote_share = async { let private_config = Object; let codex_token = await ; // 领取分红前,需要调用 opencast 打开铸币池 await codex_token; } ;
领取挖矿分红
合约账户: relay.token, codex.token
参数:
chain: 代币所在链的名称
quantity: 领取分红数量, 当前数量没有作用,主要识别代币符号, 可填 “0.0000 token_symbol”receiver: 领取分红的人
::: 注意 领取挖矿分红必须在同一个块opencast :::
使用示例:
const test_claim_token_share = async { let private_config = Object; let codex_token = await ; // 领取分红前,需要调用 opencast 打开铸币池 await codex_token } ;
跨链充值
跨链提现
跨链资产转账
合约名称: relay.token
参数:
from: 转出账户
to: 转入账户
chain: 链名称
amount: 转账数量
memo: 备注,可不填,不填输入空字符串
使用示例:
;
计算挖矿分红
计算投票分红
创建用户
合约账户:codex
函数: newaccount
参数:
creator: 创建者
new_name: 被创建用户名
active_public_key: active 权限所在 public key
owner_public_key: owner 权限所在 public key
使用示例:
const test_create_account = async { let token = await ; await token;};
更改账户权限
合约账户:codex
参数:
name: 修改权限账户名
perm_name: 需要修改的权限的名称
parent_perm_name: 需要修改的权限的父权限, 若是acitve, 父权限为owner. 若是owner, 父权限为’’
public_key: 将账户下的权限转移到当前公钥
使用示例:
获取交易记录
参数:
account_name: 查询当前账户的交易记录
pos: 从哪条记录开始查询; 若是需要从最近开始查询,使用-1,offset 设为 负数, 若要查询更多,获取查询记录最后一条的 account_action_seq 作为pos
offset: 查询的条怒
使用示例:
;
解析交易记录中的data数据
参数:
data: 交易记录中action中的data字段,类似 "0000000a5dba3055000000c0d483a93ba0860100000000000443445800000000" 这类结构 contract_name: data所在action的合约账户 action_name: data所在action的合约方法
使用示例:
const abi_bin_to_json = async { let token = await ; let struct = tokenfcstructs; let buf buf_res; try buf = Buffer; buf_res = Fcbuffer console; catche throw e; return buf_res;}
私钥生成
使用示例:
const ecc Fcbuffer = Codexmodules; const randomKey = async { let private_key = await ecc; console; return private_key; } ;
公钥获取
使用示例:
const privateToPublic = { let public_key = ecc; return public_key; } ;
获取公钥下账户
参数:
public_key: 公钥
使用示例: