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这边好像有问题,挖个坑回头填。