本篇文章给大家分享的是有关scatter配合硬件钱包怎样实现EOS离线签名,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
自己写个scatter调用,配合cleos可以实现任意命令调用。
1、scatter导入硬件钱包账号
2、新建index.html,完整源码如下
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>scatter离线签名</title>
<script src="https://cdn.scattercdn.com/file/scatter-cdn/js/latest/scatterjs-core.min.js"></script>
<script src="https://cdn.scattercdn.com/file/scatter-cdn/js/latest/scatterjs-plugin-eosjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/eosjs@16.0.9/lib/eos.min.js"></script>
</head>
<body>
正在调用scatter..
<script>
// Don't forget to tell ScatterJS which plugins you are using.
ScatterJS.plugins( new ScatterEOS() );
// Networks are used to reference certain blockchains.
// They let you get accounts and help you build signature providers.
const network = {
blockchain:'eos',
protocol:'https',
host:'nodes.get-scatter.com',
port:443,
chainId:'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'
}
// First we need to connect to the user's Scatter.
ScatterJS.scatter.connect('My-App').then(connected => {
// If the user does not have Scatter or it is Locked or Closed this will return false;
if(!connected) return false;
const scatter = ScatterJS.scatter;
// Now we need to get an identity from the user.
// We're also going to require an account that is connected to the network we're using.
const requiredFields = { accounts:[network] };
scatter.getIdentity(requiredFields).then(() => {
// Always use the accounts you got back from Scatter. Never hardcode them even if you are prompting
// the user for their account name beforehand. They could still give you a different account.
const account = scatter.identity.accounts.find(x => x.blockchain === 'eos');
// You can pass in any additional options you want into the eosjs reference.
const eosOptions = { expireInSeconds:60 };
// Get a proxy reference to eosjs which you can use to sign transactions with a user's Scatter.
const eos = scatter.eos(network, Eos, eosOptions);
// ----------------------------
// Now that we have an identity,
// an EOSIO account, and a reference
// to an eosjs object we can send a transaction.
// ----------------------------
// Never assume the account's permission/authority. Always take it from the returned account.
const transactionOptions = { authorization:[`${account.name}@${account.authority}`] };
const result = eos.transaction({
actions: [{
"account": "eosio",
"name": "linkauth",
"authorization": [{
"actor": "aaaaaaaaaaa",
"permission": "active"
}
],
"data": "500f75193bc969c40000000000ea305580d3355c5de94c44000000e02ae94c44"
}
]
}).catch(error => {
console.error(error);
});
console.log('Success =>', JSON.stringify(result));
}).catch(error => {
// The user rejected this request, or doesn't have the appropriate requirements.
console.error(error);
});
});
</script>
</body>
</html>
3、使用cleos命令配合参数-d -s生成未签名交易,拷贝交易里的actions替换掉代码里的actions
4、用浏览器打开index.html,这时候就会唤出scatter登录,然后授权,最后在硬件钱包点确认
以上就是scatter配合硬件钱包怎样实现EOS离线签名,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/1432928/blog/3071706