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中的文档,以肯定将其包含在项目中的最好要领。

上一篇:引见

下一篇:生意业务

    原文作者:博弈
    原文地址: https://segmentfault.com/a/1190000017550693
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞