DAPP开发入门——啊哈!scatterJS!

Scatter是啥

scatter是一个挺好用的桌面端的钱包把,之前是有谷歌浏览器的插件的,但是插件已经停止维护了,是有bug的,挺大的bug的(之前开发遇到一个问题,整半天是插件的问题,太惨了)所以推荐大家下载桌面端钱包,前端dapp拉起钱包的代码都是一样的。下载到官网就阔以!

scatter中的配置

因为这篇博客做的dapp开发都是基于麒麟测试网的,所以scatter钱包的网络设置也需要将麒麟测试网添加进去。
在这里插入图片描述
修改成如图所示即可:在这里插入图片描述
再导入自己的私钥对,会自动计算公钥的
在这里插入图片描述
scatter的设置本博客介绍的不是很完整,留个坑回头补把~网上资料也挺多滴

scatter with js

install packages

npm i -S scatterjs-core
npm i -S scatterjs-plugin-eosjs2

这里安装后运行遇到了一个坑,官方文档给出了解决办法

If you’re having trouble packaging or compiling your project you
probably need to add a babel transpiler.

npm i -D @babel/runtime <-- run this command and it should compile.

前端拉起钱包

const { Api, JsonRpc } = require('eosjs');
var ScatterJS =require('scatterjs-core');
var ScatterEOS =require('scatterjs-plugin-eosjs2');

ScatterJS.plugins(new ScatterEOS());

  const network = ScatterJS.Network.fromJson({
      blockchain:'eos',
      chainId:'5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191',
      host:'api-kylin.eoslaomao.com',
      port:443,
      protocol:'https'
  });
  const rpc = new JsonRpc(network.fullhost());

  ScatterJS.connect('YourAppName', {network}).then(connected => {
      if(!connected) return console.error('no scatter');

      const eos = ScatterJS.eos(network, Api, {rpc, beta3:true});

      ScatterJS.login().then(id => {
          if(!id) return console.error('no identity');
          const account = ScatterJS.account('eos');

          eos.transact({
            actions:[{
              account:"zjubcatokens",
              name:"transfer",
              authorization:[{
                actor:account.name,
                permission:account.authority
              }],
              data:{
                from: this.$store.state.account.name,
                to: 'yangjiani255',
                quantity: "1.0000 ZJUBCA",
                memo: "try some thing",
              }
            }]
          }, {
              blocksBehind: 3,
              expireSeconds: 30,
          }).then(res => {
              console.log('sent: ', res);
          }).catch(err => {
              console.error('error: ', err);
          });
      });
  });

啊,nodejs这边好像有问题,挖个坑回头填。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值