Code Monkey home page Code Monkey logo

fibos.js's Introduction

FIBOS.JS

NPM version

General purpose library for FIBOS and EOSIO blockchains.

Geting Started

Install the module with:

npm install fibos.js

Starting FIBOS&EOSIO blockchains journey with fibos.js:

var FIBOSJS = require('fibos.js')

config = {
	chainId: 'Chain ID', // 32 byte (64 char) hex string
	keyProvider: ['PrivateKey'], // WIF string or array of keys..
	httpEndpoint: 'http://127.0.0.1:8888',
	expireInSeconds: 60,
	broadcast: true,
	verbose: false, // API activity
	sign: true
}

var fibos = FIBOSJS(config);

Test

npm test

BLOCKCHAIN Support

Features

fibos.js adds a set of synchronous version method on eosjs.

Documentation

Compared with eosjs, fibos.js did not add new functions, the developer documentation can refer to eosjs. You could find all functions on eosjs project page. For fibos.js, the only thing you need to do is to switch those awful asynchronous function calls to the synchronous version.

For example,

// old-fashioned
fibos.getInfo((error, result) => { console.log(error, result) })

// stylish usage
var chainId = fibos.getInfoSync().chain_id;

Also, you could find use cases in test/test.js. With these cases, you will find out the parameters you should pass and the return values you expected.

At the moment, preliminary development on fibos.js has been completed, but there are still a lot of work to be done, such as improving the use cases. After that, you will see more advancing usages with fibos.js.

API Usage

General Configuration Before Use API

var FIBOS = require('fibos.js');
var config = {
	"chainId": "Chain ID",// 32 byte (64 char) hex string
	"producer-name": "eosio",
	"public-key": "producer public key ",
	"private-key": "producer private key",
	"httpEndpoint": "http://127.0.0.1:8888",
};

var fibos = FIBOS({
	chainId: config["chainId"],
	keyProvider: config["private-key"],
	httpEndpoint: config["httpEndpoint"],
	logger: {
		log: null,
		error: null
	}
});

1.Get Block Info

fibos.getBlockSync("block_number");

2.Get Head_Block Number

fibos.getInfoSync().head_block_num;

3.Get Last_Irreversiable_Block Number

fibos.getInfoSync().last_irreversible_block_num;

4.Create A New FIBOS Account

fibos.newaccountSync({
    creator: 'eosio',
    name: "hellomongodb",
    owner: config["public-key"],
    active: config["public-key"]
});

5.Get Account Balance

For FIBOS Network:

When you can get account balance,token name must be with suffix.("EOS@eosio")

fibos.getCurrencyBalanceSync("eosio.token", "your acount name", "EOS@eosio");

For EOS Network:

fibos.getCurrencyBalanceSync("eosio.token", "your acount name", "EOS");

6.Get Account Info

fibos.getAccountSync(account);

7.Make a successful transfer

var ctx = fibos.contractSync("eosio.token");
api1: ctx.transferSync(from, to, quality, memo);
api2: ctx.extransferSync(from, to, quality, memo, {
			authorization: from
		});

8.Generate FIBOS publickey and privatekey

var privateKey = fibos.modules.ecc.randomKeySync();//privateKey 
fibos.modules.ecc.privateToPublic(privateKey);//publickey

9.Token contract api

There are two kinds of token in FIBOS : classic token and smart token .

1). create token

接口

excreateSync(issuer, maximum_supply,  connector_weight, maximum_exchange,reserve_supply, reserve_connector_balance, {
    authorization: issuer
});

参数解释

参数 含义
issuer 通证发行者
maximum_supply 最大可发行通证数量
connector_weight 连接器权重(值为0时表示为普通通证,0-1之间为智能通证)
maximum_exchange 最大可兑换(流通)的通证数量
reserve_supply 未流通通证数量
reserve_connector_balance 未流通通证保证金数量

实例

//初始化 fibos 客户端
...
let name = "fibostest123";
let ctx = fibos.contractSync("eosio.token");
let r = ctx.excreateSync(name, "100000000000.0000 AAA",  0.15,'10000000000.0000 AAA', '3000000000.0000 AAA', '90000.0000 FO', {
    authorization: name
});
console.log(r);excreateSync(issuer, maximum_supply,  connector_weight, maximum_exchange,reserve_supply, reserve_connector_balance, {
    authorization: issuer
});

2).issue token

接口

exissueSync(to, quality, memo, {
				authorization: issuer
			})

参数解释

参数 含义
to 增发通证接收账号
quality 数量
memo 附言
authorization 发行方

实例

//初始化 fibos 客户端
...
let name = "fibostest123";
let ctx = fibos.contractSync("eosio.token");
let r = ctx.exissueSync(name, "1000000.0000 ABC", "issue to fibostest123", {
				authorization: name
			})
console.log(r);

只有普通通证支持增发

3).retire token

接口

exretireSync(from, quantity, memo, {
				authorization: from
			});

参数解释

参数 含义
from 销毁通证接收账号
quality 数量
memo 附言
authorization 销毁通证账号权限

实例

//初始化 fibos 客户端
...
let name = "fibostest123";
let ctx = fibos.contractSync("eosio.token");
let r = ctx.exretireSync(name, "1000000.0000 ABC", "retire token", {
				authorization: name
			})
console.log(r);

4).close token

接口

exissueSync(owner, symbol, {
				authorization: owner
			})

参数解释

参数 含义
owner 通证持有者账号
symbol 通证代号
authorization 通证持有者账号权限

实例

//初始化 fibos 客户端
...
let owner = "fibostest123";
let ctx = fibos.contractSync("eosio.token");
let r = ctx.exissueSync(owner, "0.0000 ABC", {
				authorization: owner
			})
console.log(r);

5).destory token

接口

exdestroySync(symbol, {
				authorization: issuer
			})

参数解释

参数 含义
symbol 通证符号
authorization 通证发行者权限

实例

//初始化 fibos 客户端
...
let issuer = "fibostest123";
let ctx = fibos.contractSync("eosio.token");
let r = ctx.exdestroySync("0.0000 ABC", {
				authorization: issuer
			})
console.log(r);

10.To be continued...

If you want get more api usage or use FIBOS node service,please go to fibos.io !

License

fibos.js is MIT licensed.

fibos.js's People

Contributors

xicilion avatar fengluo avatar luoyhang003 avatar fiber-man avatar pinelliac avatar jkyochen avatar tinyhill666 avatar wwbweibo avatar zzhtom avatar

Stargazers

 avatar 5l1v3r1 avatar kilmas avatar antain avatar nataila avatar Mu avatar rayjun avatar Matt Yao avatar  avatar  avatar Stephen Lee avatar yournian avatar  avatar Charliex2 avatar Biu avatar undefined avatar  avatar  avatar 0x57 avatar Mutalisk avatar  avatar Denis avatar paradox avatar mind avatar Kevin avatar  avatar 一回 avatar igaozp avatar yelo avatar onemedicine avatar EmiyaGm avatar Kaicong Huang avatar 张三的歌727 avatar 王阳 avatar senze.fan avatar watson1101 avatar Lakewis avatar Mr.Q avatar Peter Hu avatar Tesla Lee avatar nasa.wang avatar alang avatar LC avatar lisheng avatar baijunyao avatar 悔惜晟 avatar Ferwoo avatar zhihao avatar Virgil Sun avatar Onet away avatar  avatar LowesYang avatar liuyanghejerry avatar Clay avatar Justson avatar xiaomao Feng avatar halfrost avatar Funarp avatar Ricky Zhou avatar 张云龙 avatar Zehang Lin avatar JeLewine avatar  avatar 王亟亟 avatar  avatar Johnnie avatar Devin Woo avatar xsk-sky avatar NSHYJ avatar 冯淼森 avatar Kay avatar  avatar Mengshi.Lin avatar  avatar Chris Wen avatar Joshua Astray avatar Haocheng Li avatar  avatar Robin Wen avatar 天涯点棋子 avatar  avatar hzuhyb avatar Yang Wen avatar pengcheng avatar  avatar  avatar jasper avatar YuChao Liang avatar  avatar Orkhan ALIYEV avatar matrixbirds avatar xmen.lin avatar Le.Cheng avatar eos21 avatar  avatar ScarletMu avatar Heyward Fann avatar  avatar Tony Chen avatar VVK avatar

Watchers

James Cloos avatar Xavier avatar badyoung avatar yangtao avatar 冯淼森 avatar vnduifw avatar crazybits avatar koalaa avatar  avatar  avatar  avatar  avatar  avatar Biu avatar  avatar  avatar  avatar

fibos.js's Issues

fibos.js 不能正常的抛出类型不匹配的错误

最小用例:

it('destroy asset missing contract suffix', () => {
    let ctx = fibos.contractSync("eosio.token");
    assert.throws(() => {
        let r = ctx.exdestroySync(`0.0000 FO`, {
            authorization: "fibos"
        });
    });
})

此处,缺少了contract。正确参数应为0.0000 FO@eosio,但是 fibos.js 未能抛出类型不匹配的错误,导致 catch 不到。

bug: fibos.claimrewardsSync(key)

/home/src/fibos/node_modules/@noble/curves/secp256k1.js:8:26
const weierstrass_js_1 = require("./abstract/weierstrass.js");
^
Error: /home/src/fibos/node_modules/@noble/curves/abstract/weierstrass.js:920:62
const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine(); // R = u1⋅G + u2⋅P
^
SyntaxError: Unexpected token .
at /home/src/fibos/node_modules/@noble/curves/secp256k1.js:8:26
at /home/src/fibos/node_modules/ethereum-cryptography/secp256k1.js:4:19
at /home/src/fibos/node_modules/@ethereumjs/util/dist/constants.js:5:21
at /home/src/fibos/node_modules/@ethereumjs/util/dist/index.js:21:14
at /home/src/fibos/node_modules/web3-utils/lib/utils.js:25:22
at /home/src/fibos/node_modules/web3-utils/lib/index.js:24:13
at /home/src/fibos/node_modules/web3-eth-abi/lib/index.js:24:13
at /home/src/fibos/node_modules/fibos.js/lib/patch_api.js:1:85
at /home/src/fibos/node_modules/fibos.js/lib/index.js:5:11
at /home/src/fibos/claim.js:1:88
at /home/src/fibos/node_modules/@noble/curves/secp256k1.js:8:26
at /home/src/fibos/node_modules/ethereum-cryptography/secp256k1.js:4:19
at /home/src/fibos/node_modules/@ethereumjs/util/dist/constants.js:5:21
at /home/src/fibos/node_modules/@ethereumjs/util/dist/index.js:21:14
at /home/src/fibos/node_modules/web3-utils/lib/utils.js:25:22
at /home/src/fibos/node_modules/web3-utils/lib/index.js:24:13
at /home/src/fibos/node_modules/web3-eth-abi/lib/index.js:24:13
at /home/src/fibos/node_modules/fibos.js/lib/patch_api.js:1:85
at /home/src/fibos/node_modules/fibos.js/lib/index.js:5:11

client.transaction会中断http请求

client.transaction(tr => {
    tr.buyrambytes({
        payer: foaccount,
        receiver: receiver,
        bytes: ramnum
    })
}).then((result) => {
    console.info(result);
    req.response.write(JSON.stringify(result));
}).catch((err) => {
    // console.log(err);
});

这段代码会导致http请求自动挂断。
还没等then里面req.response.write执行
浏览器端http请求已经挂断了。

安装报错 ubuntu-18.04

ubuntu-18.04

fibos: error while loading shared libraries: libicuuc.so.55: cannot open shared object file: No such file or directory

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.