eosjs 文档(浏览器)

浏览器

用法

npm run build-webyarn build-web

为所有交易重用api对象,它缓存ABI以减少网络使用,只调用一次new eosjs_api.default(...)

<pre style="width: 100%; height: 100%; margin:0px; "></pre>

<script src='dist-web/eosjs-api.js'></script>
<script src='dist-web/eosjs-jsonrpc.js'></script>
<script src='dist-web/eosjs-jssig.js'></script>
<script>
  let pre = document.getElementsByTagName('pre')[0];
  const defaultPrivateKey = "5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr"; // useraaaaaaaa
  const rpc = new eosjs_jsonrpc.default('http://127.0.0.1:8888');
  const signatureProvider = new eosjs_jssig.default([defaultPrivateKey]);
  const api = new eosjs_api.default({ rpc, signatureProvider });

  (async () => {
    try {
      const result = await api.transact({
        actions: [{
            account: 'eosio.token',
            name: 'transfer',
            authorization: [{
                actor: 'useraaaaaaaa',
                permission: 'active',
            }],
            data: {
                from: 'useraaaaaaaa',
                to: 'useraaaaaaab',
                quantity: '0.0001 SYS',
                memo: '',
            },
        }]
      }, {
        blocksBehind: 3,
        expireSeconds: 30,
      });
      pre.textContent += '\n\nTransaction pushed!\n\n' + JSON.stringify(result, null, 2);
    } catch (e) {
      pre.textContent = '\nCaught exception: ' + e;
      if (e instanceof eosjs_jsonrpc.RpcError)
        pre.textContent += '\n\n' + JSON.stringify(e.json, null, 2);
    }
  })();
</script>

调试

如果你想要可读的源文件进行调试,请将文件引用更改为dist-web/debug目录下的-debug.js文件,这些文件只用于开发,因为它们的大小是缩小了10倍多的版本,导入调试版本将增加最终用户的加载时间。

IE11和Edge支持

如果你需要支持IE11或Edge,你还需要安装文本编码的polyfill,因为eosjs签名依赖于IE11和Edge不提供的TextEncoder。将TextEncoderTextDecoder传递给API构造函数,请参阅https://github.com/inexorabletash/text-encoding中的文档,以确定将其包含在项目中的最佳方法。


上一篇:介绍
下一篇:交易
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值