這篇文章主要為大家展示了“基于區(qū)塊鏈柚子錢(qián)包前端插件scatter如何使用”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“基于區(qū)塊鏈柚子錢(qián)包前端插件scatter如何使用”這篇文章吧。
成都創(chuàng)新互聯(lián)主營(yíng)潞城網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,APP應(yīng)用開(kāi)發(fā),潞城h5小程序設(shè)計(jì)搭建,潞城網(wǎng)站營(yíng)銷推廣歡迎潞城等地區(qū)企業(yè)咨詢
安裝和使用
npm i scatterjs-core scatterjs-plugin-eosjs eosjs -D //main.js import ScatterJS from "scatterjs-core"; import ScatterEOS from "scatterjs-plugin-eosjs"; import Eos from "eosjs"; ScatterJS.plugins(new ScatterEOS());
網(wǎng)絡(luò)鏈
// EOS公鏈(正式環(huán)境) let main = { protocol: "https", blockchain: "eos", host: "nodes.get-scatter.com", port: 443, chainId: "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", }; // 測(cè)試鏈 (就是用來(lái)測(cè)試的) let jungle2 = { protocol: "http", blockchain: "eos", host: "jungle2.cryptolions.io", port: 80, chainId: "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473", };
調(diào)試和配置
翻墻下載scatter
插件安裝。
1、打開(kāi)scatter
---setting
--network
---新建把jungle2
的信息填到對(duì)應(yīng)的位置,(取名隨便取,jungle2
)--保存
2、生成秘鑰對(duì),一鍵生成私鑰和公鑰
生成秘鑰對(duì)的地址https://eostea.github.io/eos-generate-key/
3、新建測(cè)試賬號(hào),需要填入剛才的公鑰,賬號(hào)名是z-a
,1-5
長(zhǎng)度 12 位組合
新建測(cè)試賬號(hào)的地址https://monitor.jungletestnet.io/#account
4、充值,賬號(hào)建立成功之后莫有錢(qián), 可以先充值 100 塊。測(cè)試的時(shí)候省著點(diǎn)用
充值的地址http://monitor.jungletestnet.io/#faucet
5、測(cè)試鏈上的賬號(hào)建好之后,打開(kāi)scatter
---身份---新建,選擇剛才建立的network
=> jungle2
,然后選擇對(duì)應(yīng)的賬號(hào)。點(diǎn)導(dǎo)入---保存
這樣scatter
插件配置完畢??梢杂淇斓拈_(kāi)發(fā)了。
創(chuàng)建scatter
ScatterJS.scatter.connect("app").then((connected) => { if (!connected) return false; let scatter = ScatterJS.scatter; //這里就是 window.ScatterJS = null; window.scatter = null; //通過(guò)兩種方式拿到eos 對(duì)象 // this.eos = Eos({ httpEndpoint: '', signatureProvider: ScatterJS.scatter.eosHook(jungle2) }); this.eos = scatter.eos(jungle2, Eos, { expireInSeconds: 60 }); //如果授權(quán)成功,則可以拿到用戶相關(guān)信息 if (scatter.identity) { this.account = scatter.identity.accounts.find( (x) => x.blockchain === "eos" ); } });
授權(quán)和取消授權(quán)
//授權(quán) const requiredFields = { accounts: [jungle2] }; scatter .getIdentity(requiredFields) .then(() => { //分別拿到用戶信息 和 eos 對(duì)象 this.account = scatter.identity.accounts.find( (x) => x.blockchain === "eos" ); this.eos = scatter.eos(jungle2, Eos, { expireInSeconds: 60 }, "https"); }) .catch((res) => {}); //退出 scatter.forgetIdentity().then((id) => { this.account = null; this.eos = null; });
轉(zhuǎn)賬交易部分
//取幣種相關(guān)信息 let config = { account: "xxx", //賬號(hào)名稱 code: "eosio.token", //合約名稱 symbol: "ETH", //幣種 }; eos.getCurrencyBalance(config).then((e) => { console.log(e); }); //取用戶相關(guān)信息 eos.getAccount({ account_name: "xxx" }).then((res) => { // console.log(res) let totoal = res.core_liquid_balance; //余額 let cpu = res.cpu_limit; //CPU let net = res.net_limit; //NET }); //發(fā)起轉(zhuǎn)賬 // eos.transfer('發(fā)送方帳號(hào)', '接收方帳號(hào)', '0.3000 DEV','memo', options, callback) eos .transfer(account.name, user, `${coin} EOS`, memo, transactionOptions) .then((trx) => { // That's it! console.log(`Transaction ID: ${trx.transaction_id}`); //有transaction_id 就代表轉(zhuǎn)賬成功了 }) .catch((res) => {}); //還可以使用對(duì)象 eos.transfer({ from: "發(fā)送方帳號(hào)", to: "接收方帳號(hào)", quantity: "0.1000 DEV", memo: "備注", callback, });
交互部分
// 獲取Table行數(shù)據(jù) eosjs.getTableRows({"scope":'合約名字', "code":'合約名字', "table":"game", "json": true},callback) //執(zhí)行合約上的函數(shù) eos.contract("合約名字").then(actions => { //actions隨便起的變量名 actions.test('hello', { //test是方法名, 'hello'是該actions合約test方法的參數(shù) authorization: [{actor:'lilei'}] //lilei是建立該合約的用戶 }).then(result => { console.log(result); });
以上是“基于區(qū)塊鏈柚子錢(qián)包前端插件scatter如何使用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前題目:基于區(qū)塊鏈柚子錢(qián)包前端插件scatter如何使用
網(wǎng)頁(yè)地址:http://chinadenli.net/article36/gesosg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、微信公眾號(hào)、小程序開(kāi)發(fā)、網(wǎng)站維護(hù)、網(wǎng)頁(yè)設(shè)計(jì)公司、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)