FIBOS.JS
FIBOS and EOSIO blockchain common library.
Basic
Various ways to manipulate user account information in a blockchain
Get client example
the example of linking to a test network
1 | var FIBOS = require('fibos.js'); |
getInfo
Get block info
1 | fibos_client.getInfo(); |
Example
Synchronous:
1 | var getInfo = fibos_client.getInfoSync(); |
Asynchronous:
1 | fibos_client.getInfo().then(getInfo => { |
Return
1 | { |
Return value parameter
server_version: text server-end version
chain_id:string blockchain id
head_block_num: number current block hight
last_irreversible_block_num: number Irreversible block hight
last_irreversible_block_id: string Irreversible block id
head_block_id: string Current block id
head_block_time: date Current block time
head_block_producer: string Current block producer
virtual_block_cpu_limit: number virtual block cpu limit
virtual_block_net_limit: number Virtual block NET limit
block_cpu_limit: number Block cpu limit
block_net_limit: number Block NET limit
server_version_string: string Server-end version string
getBlock
Get block info
1 | fibos_client.getBlock(block_number); |
Parameter
- block_number: int Block hright
Example
Synchronous:
1 | var getBlock = fibos_client.getBlockSync(1); |
Asynchronous:
1 | fibos_client.getBlock(1).then(getInfo => { |
Return
1 | { |
getTableRows
Returns the data in the specified table
1 | fibos_client.getTableRows(json, code, scope, table); |
Parameter
- json: boolean Wether show in clear text
- code:string contract name
- scope: string FIBOS account name
- table: string table name
Example
Synchronous:
1 | var rs = fibos_client.getTableRowsSync(true, 'contract name', 'Your FIBOS account name', 'accounts'); |
Asynchronous:
1 | fibos_client.getTableRows(true, 'contract name', 'Your FIBOS account name', 'accounts').then(rs=>{ |
contract
call contract
1 | fibos_client.contract(contract_name); |
Parameter
- contract_name: string contract name
Example
Synchronous:
1 | //Init fibos client |
Asynchronous:
1 | //Init fibos client |
ecc module
Elliptic curve encryption function,Multiple methods are built in to generate the secret keys we need
unsafeRandomKey()
Generate unsafe test key
1 | fibos.modules.ecc.unsafeRandomKey(); |
Renturn value
- Synchronous: String
- Asynchronous: Promise
return a testing private key
Example
Synchronous:
1 | var privateKey = fibos.modules.ecc.unsafeRandomKeySync(); |
Asynchronous:
1 | fibos.modules.ecc.unsafeRandomKey().then(unsaferandomkey=>{ |
randomKey()
generate random private key
1 | fibos.modules.ecc.randomKey(); |
return value
- Synchronous: String
- Asynchronous: Promise
return an random key
Example
Synchronous:
1 | var randomKey=fibos.modules.ecc.randomKeySync(); |
Asynchronous:
1 | fibos.modules.ecc.randomKey().then(randomKey=>{ |
seedPrivate()
The same seed produces the same private key each time, using at least 128 random bits to produce a secure private key.
1 | ecc.seedPrivate(seed); |
Parameter
- seed: string String of arbitrary length
return value
- Synchronous: String
- Asynchronous: Promise
return private key
Example
Synchronous:
1 | var seedPrivate=fibos.modules.ecc.seedPrivateSync(seed);//arbitrary string |
Asynchronous:
1 | fibos.modules.ecc.seedPrivate(seed).then(seedprivate=>{ |
privateToPublic()
use private key info to calculate the info of public key
1 | fibos.modules.ecc.privateToPublic(PrivateKey); |
Parameter
- PrivateKey :PrivateKey private key
- pubkey_prefix: string public key prefix(optional, default
'EOS'
)
return value
- Synchronous: String
- Asynchronous: Promise
return public key
Example
Synchronous:
1 | var privateToPublic=fibos.modules.ecc.privateToPublicSync(PrivateKey);//private key |
Asynchronous:
1 | fibos.modules.ecc.privateToPublic(PrivateKey).then(privatetopublic={ |
isValidPublic()
Determines whether the public key is valid
1 | fibos.modules.ecc.isValidPublic(pubkey); |
Parameter
- pubkey: pubkey public key
- pubkey_prefix: string public key prefix(optional,default
'EOS'
)
return value
- Synchronous: boolean
- Asynchronous: Promise
Determines whether the public key is valid
Determines whether the public key is valid
Example
Synchronous:
1 | var isValidPublic =fibos.modules.ecc.isValidPublicSync(pubkey);//public key |
Asynchronous:
1 | fibos.modules.ecc.isValidPublic(pubkey).then(isvalidpublic=>{ |
isValidPrivate()
Determines whether the private key is valid
1 | fibos.modules.ecc.isValidPrivate(wif); |
Parameter
wif: PrivateKey private key
return value
- Synchronous: boolean
- Asynchronous: Promise
Determines validation
Example
Synchronous:
1 | var isValidPrivate=fibos.modules.ecc.isValidPrivateSync(wif);//private key |
Asynchronous:
1 | fibos.modules.ecc.isValidPrivate(wif).then(isvalidprivate=>{ |
sign()
Use the data information or hash to create the signature
1 | fibos.modules.ecc.sign(data,PrivateKey); |
Parameter
- data: String buffer
- PrivateKey: PrivateKey private key
- encoding: string data encoding(optional,default
'utf8'
)
return value
- Synchronous: string
- Asynchronous: Promise
string signature
Example
Synchronous:
1 | var sign = fibos.modules.ecc.signSync(data,PrivateKey);//string和private key |
Asynchronous:
1 | fibos.modules.ecc.sign(data,PrivateKey).then(sign=>{//string和private key |
signHash()
The signature is created using the data information hashed and private key
1 | fibos.modules.ecc.signHash(dataSha256,PrivateKe); |
Parameter
- dataSha256: string | buffer sha256 hash 32 Byte buffers or strings
- privateKey: PrivateKey private key
- encoding: string dataSha256 encoding(If it’s a string)(optional,default
'hex'
)
return value
Synchronous: string
Asynchronous: Promise
String signature with hash encryption
Example
Synchronous:
1 | var signHash = fibos.modules.ecc.signHashSync(dataSha256,PrivateKey);//hash encryption string and private key |
Asynchronous:
1 | fibos.modules.ecc.signHash(dataSha256,PrivateKe).then(signhash=>{//hash encryption string and private key |
verify()
validate signature data
1 | fibos.modules.ecc.verify(signature,data,pubkey); |
Parameter
- signature: string | buffer Buffer or hexadecimal string
- data: string | buffer string buffer
- pubkey: pubkey | PublicKey public key
return value
- Synchronous: boolean
- Asynchronous: Promise
Determine whether the signature data is valid
Example
Synchronous:
1 | var verify = fibos.modules.ecc.verifySync(signature, data, pubkey);//signature,string,public key |
Asynchronous:
1 | fibos.modules.ecc.verify(signature, data, pubkey).then(verify=>{//signature,string,public key |
verifyHash()
validate signature hash data
1 | fibos.modules.ecc.verifyHash(signature, hashData, pubkey); |
Parameter
- signature: string | buffer Buffer or hexadecimal string
- hashData: boolean|sha256 Hash data(optional,default
true
) - pubkey: pubkey | PublicKey public key
- encoding: string encoding(optional,default
'utf8'
)
return value
- Synchronous: boolean
- Asynchronous: Promise
Validation
Example
Synchronous:
1 | fibos.modules.ecc.verifyHash(signature, sha256, pubkey);//signature, hash string,public key |
Asynchronous:
1 | fibos.modules.ecc.verifyHash(signature, sha256, pubkey).then(verifyhash=>{//signature, hash string,public key |
recover()
revocery public key used for create signature
1 | fibos.modules.ecc.recover(signature, data); |
Parameter
- signature: string | buffer(EOSbase58sig ..,Hex,Buffer)
- data: string | buffer full data
- encoding: string data encoding(if data is a string)(optional, default
'utf8'
)
return value
- Synchronous: string
Asynchronous: Promise
return public key
Example
Synchronous:
1 | var recover = fibos.modules.ecc.recoverSync(signature, data);//signature,数据 |
Asynchronous:
1 | fibos.modules.ecc.recover(signature, 'I am alive').then(recover=>{//signature,数据 |
recoverHash()
Recover public key used to create hash signature
1 | fibos.modules.ecc.recoverHash(signature,dataSha256); |
Parameter
- signature: string | buffer(EOSbase58sig ..,Hex,Buffer)
- dataSha256: string | buffer sha256 string 32 byte buffer or hexadecimal string
- encoding: string |dataSha256 encoding(if dataSha256 is a string)(optional, default
'hex'
)
return value
- Synchronous: string
- Asynchronous: Promise
reture an public key
Example
Synchronous:
1 | var recoverHash = fibos.modules.ecc.recoverHash(signature,dataSha256 );//signature, hash string |
Asynchronous:
1 | fibos.modules.ecc.recoverHash(signature, dataSha256).then(recover_hash => {//signature, hash string |
sha256()
sha256 encryption
1 | fibos.modules.ecc.sha256(data); |
Parameter
- data: string | buffer binary data,requiring Buffer.from(data,’hex’)
- resultEncoding: string (optional, default
'hex'
) - encoding: string result encoding to ‘hex’,’binary’ or ‘base64’(optional, default
'hex'
)
return value
- Synchronous: string | buffer
- Asynchronous: Promise
Encrypted data used by hash.sha256
Example
Synchronous:
1 | var sha256 = fibos.modules.ecc.sha256(data);//string |
Asynchronous:
1 | fibos.modules.ecc.sha256(data).then(recover_hash => { |
System Contract
newaccount
Create a new FIBOS account
1 | fibos_client.newaccount({ |
Parameter
- creator: string rreceiver account name
- name: string rreceiver account name
- owner: string rreceiver owner permission public key
- active: string rreceiver active permission public key
Example
Synchronous:
1 | fibos_client.newaccountSync({ |
Asynchronous:
1 | fibos_client.newaccount({ |
getAccount
get account info
1 | fibos_client.getAccount(account_name); |
Parameter
- account_name: string account name that need to be get
Example
Synchronous:
1 | var getAccount = fibos.getAccountSync("Account Name");//account name |
Asynchronous:
1 | fibos_client.getAccount("Account Name").then(getAccount => {//account name |
return value
1 | { |
buyrambytes
The creator calls this method to buy memory for the creator to store information about the new account
1 | fibos_client.buyrambytes({ |
Parameter
payer:string creator account name
receiver: string receiver account name
bytes: number Memory size consumed (bytes)
Example
1 | fibos_client.buyrambytes({ |
delegatebw
Mortgage tokens to obtain CPU and NET resources
1 | fibos_client.delegatebw({ |
Parameter
from: string The name of the mortgagor’s account
receiver: string The account name of the resource recipient
stake_net_quantity: string The creator mortgages FO to get NET for the creator
stake_cpu_quantity: string The creator mortgages FO to the creator to get the CPU
transfer: number usually use 1 to get resources for someone else to mortgage FO, and if you want to get resources for yourself you need to change it to 0
Example
1 | fibos_client.delegatebw({ |
Token Contract
There are two types of token in FIBOS: classic token and intelligent token
transfer
Configured EOS MainNet and EOS RPC address and EOS private key and then initialize a EOS, client by calling a transferSync
method, realize the transfer operation
1 | ctx.transfer(from, to, quantity, memo, { |
Parameter
- form: string The transferor
- to: string The transferee
- quantity: number amount 1.0000 EOS
- memo: string note
- authorization: string authorization
Example
Synchronous:
1 | let r = ctx.transferSync('FROM Account Name', 'fiboscouncil', '11 FO', 'transfer 11 FO FROM xxx to xxx', { |
Asynchronous:
1 | ctx.transfer('FROM Account Name', 'fiboscouncil', '11 FO', 'transfer 11 FO FROM xxx to xxx', { |
exchange
Use Bancor for token conversion in FIBOS
1 | ctx.exchange(owner, quantity, tosym, memo, { |
Parameter
- owner: string exchange account name
- quantity: number exchange token amount
- tosym: string exchange token type
- memo: string note
- authorization: string authorization
Example
Synchronous:
1 | var result = ctx.exchangeSync('Owner Account', '1.0000 VO@fibostest123', '0.0000 FO@eosio', memo, { |
Asynchronous:
1 | ctx.exchange('Owner Account', '1.0000 VO@fibostest123', '0.0000 FO@eosio', memo, { |
excreate
Call the token contract excreate
interface to access token issue
1 | ctx.excreate(issuer, maximum_supply, connector_weight, maximum_exchange, reserve_supply, reserve_connector_balance, expiration, buy_fee,sell_fee,connector_balance_issuer,{ |
Method Parameter
- issue: string Token issue account
- maximum_supply: assert Maximum number of token issued
- connector_weight: number Connector weight
- maximum_exchange: assert Maximum number of echange(circulation) tokens
- reserve_supply: assert Not circulation token amount
- reserve_connector_balance: assert Amount of outstanding token security deposit
- expiration: time_point_sec Project lock period preset by the project side
- buy_fee: double transaction fee of token presets by project party
- sell_fee: double Cashing fee presets by project party
- connector_balance_issuer: string Reserve publisher
- authorization: string permission
Example
Issuing common token
Synchronous:
1 | //init fibos client |
Asynchronous:
1 | /init fibos client |
Issuing smart token
Synchronous:
1 | //init fibos client |
Asynchronous:
1 | //init fibos client |
exissue
additional token issuing
1 | ctx.exissue(issuer, maximum_supply, connector_weight, maximum_exchange, reserve_supply, reserve_connector_balance, expiration, { |
Parameter
- issuer: string token issuer account
- maximum_supply: assert Maximum number of token issued
- connector_weight: number connector weight
- maximum_exchange: assert Maximum number of echange(circulation) tokens
- reserve_supply: assert Not circulation token amount
- reserve_connector_balance: assert Amount of outstanding token security deposit
- expiration: time_point_sec Project lock period preset by the project side
- authorization: string permission
Example
Synchronous:
1 | //init fibos client |
Asynchronous:
1 | //init fibos client |
exdestroy
destroy token(the token can be destroyed only by the number of circulation is 0)
1 | ctx.exdestroy(symbol, {authorization: 'author_name'}); |
Parameter
- symbol: string Token exchange data
- authorization: string authorization
Example
Synchronous:
1 | //init fibos client |
Asynchronous:
1 | //init fibos client |
exlocktrans
Locked position(When the project party issues the smart token, the value of the parameter reserve_supply filled in by the project party will vary with the operation of destroying and unlocking the token.)
1 | ctx.exlocktrans(from, to, quantityt, expiration, expiration_to,memo, { |
method parameters
- from: string token transferor
- to: string token transferee
- quantity: number token amount
- expiration: time_point_sec lockout time of rolling out
- expiration_to: time_point_sec lockout time of rolling in
- memo: string note
- authorization: string authorization
Example
Synchronous:
1 | //init fibos client |
Asynchronous:
1 | //init fibos client |
exunlock
Unlock (the user can change the token in the lock warehouse into the token in circulation through unlock operation)
1 | ctx.exunlock(owner, quantity, expiration, memo, { |
method and parameters
- owner: owner token owner
- quantity: number unlock amount
- expiration: time_point_sec lock period
- memo: string note
- authorization: string authorization
Example
Synchronous:
1 | //init fibos client |
Asynchronous:
1 | //init fibos client |
ctxrecharge
contract sub-wallet top up
1 | ctx.ctxrecharge(owner, quantity, memo, { |
methods and parameters
- owner: string account owner
- quantity: number top up token amount
- memo: string note
- authorization: string authorization
Example
Synchronous top up:
1 | //init fibos client |
Asynchronous top up:
1 | //init fibos client |
ctxextract
contract sub-wallet withdrawal
1 | ctx.ctxextract(owner, quantity, memo, { |
method and operation
- owner: string account owner
- quantity: number top up amount
- memo: string note
- authorization: string authorization
Example
Synchronous withdrawal:
1 | //init fibos client |
Asynchronous withdrawal:
1 | //init fibos client |
ctxtransfer
Contract sub-wallet transfer
1 | ctx.ctxtransfer(from, to, quantity, memo, { |
Parameter
- from: string token transferor
- to: string token transferee
- quantity: number token amount
- memo: string note
- authorization: string authorization
Example
Synchronous transfer:
1 | //init fibos client |
Asynchronous transfer:
1 | //init fibos client |