yoshikazzz / burnweb Goto Github PK
View Code? Open in Web Editor NEWJavascript API Library for BURN blockchain
Javascript API Library for BURN blockchain
burnweb.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1")
.then(console.log);
> "1000000000000
How to use burnweb.createStore():
var BurnWeb = require('burnweb');
var web3 = new BurnWeb(endpoint, privateKey);
burnweb.createStore(storeName).then(console.log);
Logic of burnweb.createStore():
var sign = require('./sign.js');
/*** Configure ChainId ***/
const chainId = 4329815; // get from /api/blockchain -> chain_id
/*** Configure sender ***/
const priv = Buffer.from('91b4d2f762733721eb9213b08370bb641c2ffcbf809aa78ad4d847b57e1cf604', 'hex'); // sender's private key to sign
const address = '0x4beA9f4ebBa2C63289fb257ED58dF1e0e572b1E4'; // sender's address
/*** Configure parameter here ***/
const method = '06dc8de5'; // createToken
const storeId = // auto-generate (random)
const types = ['string', 'address', 'uint256'];
var rawData = [
storeName, // name
'0x0000000000000000000000000000000000000000', // fee_token_id
'0' // fee
];
const nonce = Date.now(); // use milliseconds as nonce
const signature = sign(chainId, priv, method, tokenId, 0, nonce, types, rawData)
// Call BURN node at /api/kvs/create
return { tx_hash, storeId }
burnweb.getGasPrice()
.then(console.log);
> "20000000000"
How to use burnweb.transferToken():
var BurnWeb = require('burnweb');
var web3 = new BurnWeb(endpoint, privateKey);
burnweb.transferToken(tokenId, target, amount).then(console.log);
Logic of burnweb.transferToken():
const method = 'a9059cbb';
const rawData = [target, amount];
const nonce = Date.now(); // use milliseconds as nonce
const encoded = web3.eth.abi.encodeParameters(['address', 'uint256'], rawData);
const data = '0x' + method + encoded.toString('hex').substr(2);
const nonceHex = '0x' + nonce.toString(16);
const rawTx = {
nonce: nonceHex,
gasPrice: '0x0',
gasLimit: '0x0',
to: tokenId,
value: 0,
data: data,
};
//Call BURN node at /api/blockchain API, get "name" as "chainName" and "chain_id" as "chainId"
const customCommon = Common.default.forCustomChain(
'mainnet',
{
name: chainName,
networkId: chainId,
chainId: chainId,
},
'petersburg',
);
const tx = new Transaction(rawTx, { common: customCommon });
tx.sign(privateKey);
const signature = tx.v.toString('hex')+tx.r.toString('hex')+tx.s.toString('hex');
// Call BURN node at /api/token/:token_id/transfer
// Where :token_id = tokenId, body = {"to": target, "value": amount, "nonce": nonce, "signature": signature}
return tx_hash (returned from the API)
tokenId
parameter from `burnweb.createToken()'{ txHash, tokenId }
burnweb.getBlockNumber()
.then(console.log);
> 2744
The /api/token/:token_id
returns:
Please include it in the burnweb.getToken
return.
Returns a list of transactions for the specified token_id, from, to, start, end time range. Call the API: https://burn-network.io/api/token/:token_id/tx (https://documenter.getpostman.com/view/4068273/TVCb4AoH#9a548366-7e9e-4b33-8045-b892f16285b6)
burnweb.listTokenTransactions(tokenId, from, to, start, end)
.then(console.log);
Returns a transaction matching the given transaction hash. Call the token/:token_id
API.
burnweb.getToken('0x21c1aae22ba32bd6da27d23141103b377859d3b4')
.then(console.log);
How to use burnweb.setKeyValue():
var BurnWeb = require('burnweb');
var web3 = new BurnWeb(endpoint, privateKey);
burnweb.setKeyValue(storeName, collection, key, value).then(console.log);
Logic of burnweb.setKeyValue():
var sign = require('./sign.js');
/*** Configure ChainId ***/
const chainId = 4329815; // get from /api/blockchain -> chain_id
/*** Configure sender ***/
const priv = Buffer.from('91b4d2f762733721eb9213b08370bb641c2ffcbf809aa78ad4d847b57e1cf604', 'hex'); // sender's private key to sign
const address = '0x4beA9f4ebBa2C63289fb257ED58dF1e0e572b1E4'; // sender's address
/*** Configure parameter here ***/
const method = 'c6be612d'; // createToken
const types = ['string', 'string', 'string'];
var rawData = [
collection,
key,
value
];
const nonce = Date.now(); // use milliseconds as nonce
const signature = sign(chainId, priv, method, tokenId, 0, nonce, types, rawData)
// Call BURN node at /api/kvs/:store_id/collections/:collection
return { tx_hash }
How to use burnweb.issueToken():
var BurnWeb = require('burnweb');
var web3 = new BurnWeb(endpoint, privateKey);
burnweb.issueToken(tokenId, target, amount).then(console.log);
Logic of burnweb.issueToken():
const method = '40c10f19';
const rawData = [to, value];
const nonce = Date.now(); // use milliseconds as nonce
const encoded = web3.eth.abi.encodeParameters(['address', 'uint256'], rawData);
const data = '0x' + method + encoded.toString('hex').substr(2);
const nonceHex = '0x' + nonce.toString(16);
const rawTx = {
nonce: nonceHex,
gasPrice: '0x0',
gasLimit: '0x0',
to: tokenId,
value: 0,
data: data,
};
//Call BURN node at /api/blockchain API, get "name" as "chainName" and "chain_id" as "chainId"
const customCommon = Common.default.forCustomChain(
'mainnet',
{
name: chainName,
networkId: chainId,
chainId: chainId,
},
'petersburg',
);
const tx = new Transaction(rawTx, { common: customCommon });
tx.sign(privateKey);
const signature = tx.v.toString('hex')+tx.r.toString('hex')+tx.s.toString('hex');
// Call BURN node at /api/token/:token_id/issue
// Where :token_id = tokenId, body = {"to": to, "value": value, "nonce": nonce, "signature": signature}
return tx_hash (returned from the API)
burnweb.createToken() を実行する際、tokenId が内部的に自動生成されるため、feeTokenId
に自身の tokenId
を指定することができない。feeTokenId
パラメータを feeToken
に名称変更し、以下の挙動に変えたい。
feeToken
== 1 の場合、生成された tokenId
を feeTokenId
に設定feeToken
== 0 の場合、0x000...000 を feeTokenId
に設定Returns a transaction matching the given transaction hash. Call the transactions/:id
API.
burnweb.getTransaction('0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b§234')
.then(console.log);
Returns a transaction matching the given transaction hash. Call the kvs/:store_id/collections/:collection/keys/:key/value
API.
burnweb.getKeyValue(storeId, collection, key)
.then(console.log);
web3.eth.accounts.privateKeyToAccount
address
and privateKey
テストコードを見ると、
const { txHash } = await burnweb.createToken(
'Name',
'USDN',
6,
20000000000000,
'0x0000000000000000000000000000000000000000',
0,
0,
'https://s3.aws.com/11980234/219315.png',
1,
0,
1234
);
burnweb.createToken の最後の引数に nonce を渡しているように見える。nonce は引数で指定せず、burnweb.createToken 内で現在時刻(ミリ秒)を指定する。
Returns a block matching the block number or block hash. Call the block_number
API endpoint.
burnweb.getBlock(3150)
.then(console.log);
burnweb.getBalanceOf(tokenId, ownerAddress)
.then(console.log);
> "1000000000000
How to use burnweb.deleteKeyValue():
var BurnWeb = require('burnweb');
var web3 = new BurnWeb(endpoint, privateKey);
burnweb.deleteKeyValue(storeName, collection, key).then(console.log);
Logic of burnweb.deleteKeyValue():
var sign = require('./sign.js');
/*** Configure ChainId ***/
const chainId = 4329815; // get from /api/blockchain -> chain_id
/*** Configure sender ***/
const priv = Buffer.from('91b4d2f762733721eb9213b08370bb641c2ffcbf809aa78ad4d847b57e1cf604', 'hex'); // sender's private key to sign
const address = '0x4beA9f4ebBa2C63289fb257ED58dF1e0e572b1E4'; // sender's address
/*** Configure parameter here ***/
const method = '668f1f1b'; // deleteKeyValue()
const types = ['string', 'string'];
var rawData = [
collection,
key
];
const nonce = Date.now(); // use milliseconds as nonce
const signature = sign(chainId, priv, method, tokenId, 0, nonce, types, rawData)
// Call BURN node at /api/kvs/:store_id/collections/:collection
return { tx_hash }
How to use burnweb.burnToken():
var BurnWeb = require('burnweb');
var web3 = new BurnWeb(endpoint, privateKey);
burnweb.burnToken(tokenId, amount).then(console.log);
Logic of burnweb.issueToken():
const method = '42966c68';
const rawData = [value];
const nonce = Date.now(); // use milliseconds as nonce
const encoded = web3.eth.abi.encodeParameters(['uint256'], rawData);
const data = '0x' + method + encoded.toString('hex').substr(2);
const nonceHex = '0x' + nonce.toString(16);
const rawTx = {
nonce: nonceHex,
gasPrice: '0x0',
gasLimit: '0x0',
to: tokenId,
value: 0,
data: data,
};
//Call BURN node at /api/blockchain API, get "name" as "chainName" and "chain_id" as "chainId"
const customCommon = Common.default.forCustomChain(
'mainnet',
{
name: chainName,
networkId: chainId,
chainId: chainId,
},
'petersburg',
);
const tx = new Transaction(rawTx, { common: customCommon });
tx.sign(privateKey);
const signature = tx.v.toString('hex')+tx.r.toString('hex')+tx.s.toString('hex');
// Call BURN node at /api/token/:token_id/burn
// Where :token_id = tokenId, body = {"value": value, "nonce": nonce, "signature": signature}
return tx_hash (returned from the API)
var BurnWeb = require('burnweb');
var burnweb = new BurnWeb('http://localhost:8545');
or specify privateKey at the same time,
var BurnWeb = require('burnweb');
var burnweb = new BurnWeb('http://localhost:8545', privateKey);
How to use burnweb.createToken():
var BurnWeb = require('burnweb');
var web3 = new BurnWeb(endpoint, privateKey);
burnweb.createToken(
tokenId,
name,
symbol,
decimals,
total_supply,
fee_token_id,
tx_fee,
tx_fee_rate,
icon,
mintable,
burnable
).then(console.log);
Logic of burnweb.createToken():
var sign = require('./sign.js');
/*** Configure ChainId ***/
const chainId = 4329815; // get from /api/blockchain -> chain_id
/*** Configure sender ***/
const priv = Buffer.from('91b4d2f762733721eb9213b08370bb641c2ffcbf809aa78ad4d847b57e1cf604', 'hex'); // sender's private key to sign
const address = '0x4beA9f4ebBa2C63289fb257ED58dF1e0e572b1E4'; // sender's address
/*** Configure parameter here ***/
const method = '78e2fc09'; // createToken(string,string,uint256,uint256,address,uint256,uint256,string,uint256,uint256)
const tokenId = '0x50c1aae22ba32bd6da27d23141103b377859d3a3';
const types = ['string', 'string', 'uint256', 'uint256', 'address', 'uint256', 'uint256', 'string', 'uint256', 'uint256'];
var rawData = [
'Nesta USD', // name
'USDN', // symbol
'6', // decimals
'20000000000000', // total_supply (string)
'0x0000000000000000000000000000000000000000', // fee_token_id
'0', // fee (string)
'1000', // fee_rate (mill-%) e.g. 1% = 1000.
'https://etherscan.io/token/images/nexo_32.png', // icon
'1', // mintable
'0', // burnable
];
const nonce = Date.now(); // use milliseconds as nonce
const signature = sign(chainId, priv, method, tokenId, 0, nonce, types, rawData)
// Call BURN node at /api/token/create
return tx_hash (returned from the API)
At the first timing of chainId needed, query Chain ID by /api /blockchain API, and cache it in bunweb
instance level.
The /api/token/:token_id
returns:
Please include them in the burnweb.getTransaction
return.
web3.eth.accounts.create
address
and privateKey
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.