eosjs开发文档

时间:2018-07-11作者:klpeng分类:IT综合浏览:4052评论:0

eosjs下载地址:https://download.csdn.net/download/weixin_39842528/10534035

bip39下载地址:https://download.csdn.net/download/weixin_39842528/10547870

 

Eosjs开发文档

实例化  eosjs

测试环境 || 开发环境

Param

keyProvider: '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'  

 

Example

 

eos  = Eos({

//私钥

keyProvider: '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'  

});

 

 

发送交易  transfer()

 

Param

 

{

    "from": "account_name", //发件人

    "to": "account_name", //收件人

    "quantity": "asset", //资产

    "memo": "string"

}

 

可选参数(after Param)

 

options = {

  authorization: 'tokyohotcoin@active', //签名交易用到的权限

  broadcast: true, //是否广播交易

  sign: true //是否签名交易

}

 

Example

 

1)公链令牌(EOS)转账

 

  1.   方式1

 

eos.transfer('tokyohotcoin', 'jailebihaido', '1.0000 EOS', '', options)

 

  1. 方式2

eos.transaction(

  {

    actions: [

      {

        account: 'eosio.token',

        name: 'transfer',

        authorization: [{

          actor: 'tokyohotcoin', //发件人

          permission: 'active' 

        }],

        data: {

          from: 'tokyohotcoin', //发件人

          to: 'jailebihaido', //收件人

          quantity: '7.0000 EOS',  //发送资产

          memo: ''

        }

      }

    ]

  }

  // options -- example: {broadcast: false} 自定义options

)

 

 

  1. 普通合约令牌(代币)转账

 

//  'myaccount' 创建合约代币(令牌的账户)

 

const myaccount = eos.contract('tokyohotcoin')

 

// 发送合约令牌

//  'test12344444'账户的私钥:    \

5KBWYsYudu9APDdUrHVPPDdyVMhjrRVq3zqDAEzhuogDR3caApb

myaccount.transfer('jailebihaido', 'test12344444', '1.000 THC', '')

查询账户余额 getCurrencyBalance()

Param

{

  "code": "name", //合约账户

  "account": "name", //被查询余额的账户

  "symbol": "optional<string>" //令牌

}

 

Example

 

  1. 查询公链代币EOS余额

 

eos.getCurrencyBalance('eosio.token','test12344444','EOS').then(EOSbalance => console.loge(EOSbalance))

 

  1. 查询合约代币余额

 

eos.getCurrencyBalance('tokyohotcoin','test12344444','THC').then(SYSbalance => console.loge(SYSbalance))

生成地址私钥  ecc.seedPrivate

1)

Param

Text : string(字符串)

 

Example

 

//根据种子生成私钥

const  wif= eos.ecc.seedPrivate('zhongzi');

//根据私钥获取公钥地址

const  pubkey = eos.ecc.privateToPublic(wif);

 

2) BIP39 根据bip39生成助记词然后生成私钥

 

 

//生成助记词

var mnemonic = BIP39.generateMnemonic();

//根据助记词生成种子

var seed = BIP39.mnemonicToSeed(mnemonic).toString(‘hex’);

//根据种子生成私钥

Var privatekey = eos.ecc.seedPrivate(seed )

创建账户  newaccount

Param

 

{

    "creator": "account_name",

    "name": "account_name",

    "owner": "authority",

    "active": "authority"

}

 

Example:

 

wif = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'

pubkey = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV'

eos.transaction(tr => {

  tr.newaccount({

    creator: 'tokyohotcoin', //创建者

    name: 'newaccountnm',//被创建的账户名

    owner: pubkey,

    active: pubkey

  })

 

  tr.buyrambytes({

    payer: 'tokyohotcoin', //支付创建账号花费的账户

    receiver: 'newaccountnm', 被创建的账户名

    bytes: 3072

  })

 

//可选

  tr.delegatebw({

    from: 'tokyohotcoin',

    receiver: 'newaccountnm',

    stake_net_quantity: '0.0010 EOS',

    stake_cpu_quantity: '0.0100 EOS',

    transfer: 0

  })

})

买卖内存 buyram || sellram

1)买入

 

Param

{

    "payer": "",

    "receiver": "",

    "quant": "0.0001 EOS"

}

 

Example

 

>eos.buyram('tokyohotcoin','tokyohotcoin','1.0000 EOS');

 

2)卖出

 

Param

{

    "account": "",

    "bytes": "1"  //单位bytes

}

 

Example

 

eos.sellram(‘'tokyohotcoin',’100’);

 

抵押,赎回net ,cpu资源  

 

1)抵押  delegatebw

Param

{

    "from": "account_name",

    "receiver": "account_name",

    "stake_net_quantity": "asset",

    "stake_cpu_quantity": "asset",

    "transfer": "bool"

}

Example

 

 eos.delegatebw({

    from: 'tokyohotcoin', //将花费资产的人

    receiver: 'tokyohotcoin',  //将获得抵押资源的人

    stake_net_quantity: '0.0010 EOS',

    stake_cpu_quantity: '0.0100 EOS',

    transfer: 0

})

  1. 赎回 undelegatebw

 

Param

{

    "from": "account_name",

    "receiver": "account_name",

    "unstake_net_quantity": "asset",

    "unstake_cpu_quantity": "asset"

}

 

Example

eos.undelegatebw({

    "from": 'tokyohotcoin',

    "receiver": 'tokyohotcoin',

    "unstake_net_quantity": "0.0010 EOS",

    "unstake_cpu_quantity": "0.0010 EOS"

})

 

验证EOS地址是否有效  ecc.isValidPublic()

Param

 

Text : pubkey(字符串)公钥地址

 

Example

 

eos.ecc.isValidPublic("EOS7mTgf22j6aFFGSm4BFf7CvWm3vzqRPcoXz6Lbk8hahDhcZ3xKM")

> true

 

验证EOS私钥是否有效  isValidPrivate

Param

 

Text : privatekey(字符串)私钥地址

 

Example

 

eos.ecc.isValidPrivate('5JBmwU6SJhSVyzqM2WYfyg9h2qop3VrCc7qSYpkBAe4aNFanXMi')

 

 

根据公钥地址获取账户名称 getKeyAccounts

Param

 

Text:public_key(字符串)公钥地址

 

Example

 

eos.getKeyAccounts('EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV').then(s => console.log(s))

 

获取账户信息及资源(ram,net,cpu等)  getaccount

Param

 

Text : account(字符串)账户

 

Example

 

eos.getAccount('tokyohotcoin');

 

返回结果 > {
    "account_name":"machaoxiaoai",
    "head_block_num":4849352,  //当前块高
    "head_block_time":"2018-07-10T01:12:31.000",
    "privileged":false,
    "last_code_update":"2018-07-04T01:46:19.000"
    "created":"2018-07-03T09:20:59.500",  //账号被创建时间
    "core_liquid_balance":"9981.7020 EOS", //账户eos余额
    "ram_quota":506617, //ram总容量 单位(bytes)
    "net_weight":1000000,
    "cpu_weight":1000000,
    "net_limit":{  //网络资源单位bytes
        "used":286
        "available":20056994,
        "max":20057280
    },
    "cpu_limit":{  //cpu资源单位 time
        "used":4904,
        "available":3822200,
        "max":3827104
    },
    "ram_usage":194836, //已经使用了的ram
    "permissions":[
        {
            "perm_name":"active",
            "parent":"owner",
            "required_auth":{
                "threshold":1,
                "keys":[
                    {
                        "key":"EOS88qZpUiRaTPjdFm1F3Uu8HiwNdWJ4STWiG1DQdJPiHDdUWxBNF",
                        "weight":1
                    }
                ],
                "accounts":Array[0],
                "waits":Array[0]
            }
        },
        {
            "perm_name":"owner",
            "parent":"",
            "required_auth":{
                "threshold":1,
                "keys":[
                    {
                        "key":"EOS88qZpUiRaTPjdFm1F3Uu8HiwNdWJ4STWiG1DQdJPiHDdUWxBNF",
                        "weight":1
                    }
                ],
                "accounts":Array[0],
                "waits":Array[0]
            }
        }
    ],
    "total_resources":{
        "owner":"machaoxiaoai",
        "net_weight":"100.0000 EOS",
        "cpu_weight":"100.0000 EOS",
        "ram_bytes":506617
    },
    "self_delegated_bandwidth":{
        "from":"machaoxiaoai",
        "to":"machaoxiaoai",
        "net_weight":"100.0000 EOS",
        "cpu_weight":"100.0000 EOS"
    },
    "refund_request":null,
    "voter_info":{
        "owner":"machaoxiaoai",
        "proxy":"",
        "producers":Array[0],
        "staked":2022000,
        "last_vote_weight":"0.00000000000000000",
        "proxied_vote_weight":"0.00000000000000000",
        "is_proxy":0
    }
}

 

 

 

喜欢的请关注一下

打赏ETH地址:

eosjs开发文档

如果你也是区块链爱好者可以添加本人QQ

eosjs开发文档

 

打赏
文章版权声明:除非注明,否则均为彭超的博客原创文章,转载或复制请以超链接形式并注明出处。
相关推荐

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

猜你喜欢