您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關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離線簽名,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。