GithubHelp home page GithubHelp logo

burnweb's People

Contributors

nayuki-passthetest avatar yoshikazzz avatar

Watchers

 avatar  avatar

burnweb's Issues

getBalance

burnweb.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1")
.then(console.log);
> "1000000000000

createStore

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 }

getGasPrice

burnweb.getGasPrice()
.then(console.log);
> "20000000000"

transferToken

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)

getToken

Returns a transaction matching the given transaction hash. Call the token/:token_id API.

burnweb.getToken('0x21c1aae22ba32bd6da27d23141103b377859d3b4')
.then(console.log);

setKeyValue

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 }

issueToken

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)

[createToken] Set feeTokenId

burnweb.createToken() を実行する際、tokenId が内部的に自動生成されるため、feeTokenId に自身の tokenId を指定することができない。feeTokenId パラメータを feeToken に名称変更し、以下の挙動に変えたい。

  • feeToken == 1 の場合、生成された tokenIdfeeTokenId に設定
  • feeToken == 0 の場合、0x000...000 を feeTokenId に設定

getTransaction

Returns a transaction matching the given transaction hash. Call the transactions/:id API.

burnweb.getTransaction('0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b§234')
.then(console.log);

getKeyValue

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);

privateKeyToAccount

  • Wrap web3.eth.accounts.privateKeyToAccount
  • Return only address and privateKey

[createToken] nonce = Date.now()

テストコードを見ると、

    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 内で現在時刻(ミリ秒)を指定する。

getBlock

Returns a block matching the block number or block hash. Call the block_number API endpoint.

burnweb.getBlock(3150)
.then(console.log);

getBalanceOf

burnweb.getBalanceOf(tokenId, ownerAddress)
.then(console.log);
> "1000000000000

deleteKeyValue

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 }

burnToken

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)

setProvider

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);

createToken

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)

[setProvider] Cache ChainID

At the first timing of chainId needed, query Chain ID by /api /blockchain API, and cache it in bunweb instance level.

[getTransaction] Add fields in return

The /api/token/:token_id returns:

  • tx_from (String)
  • tx_to (String)
  • tx_value (String)
  • fee_token_id (String)
  • gas_price (String)
  • gas_limit (String)

Please include them in the burnweb.getTransaction return.

generateAccount

  • Wrap web3.eth.accounts.create
  • Return only address and privateKey

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.