How to use the front-end plug-in scatter of grapefruit wallet based on block chain
This article mainly shows you "based on block chain grapefruit wallet front plug-in scatter how to use", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "based on block chain grapefruit wallet front-end plug-in scatter how to use" this article.
Installation and use
Npm I scatterjs-core scatterjs-plugin-eosjs eosjs-D//main.jsimport ScatterJS from "scatterjs-core"; import ScatterEOS from "scatterjs-plugin-eosjs"; import Eos from "eosjs"; ScatterJS.plugins (new ScatterEOS ())
Network chain
/ / EOS public chain (formal environment) let main = {protocol: "https", blockchain: "eos", host: "nodes.get-scatter.com", port: 443,chainId: "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",}; / / Test chain (which is used for testing) let jungle2 = {protocol: "http", blockchain: "eos", host: "jungle2.cryptolions.io", port: 80, chainId: "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473",}
Debugging and configuration
Climb over the wall to download the scatter plug-in installation.
1. Open scatter---setting--network--- and fill in the jungle2 information to the corresponding location (name whatever you want, jungle2)-- Save.
2. Generate a secret key pair, and generate a private key and a public key with one key
The address https://eostea.github.io/eos-generate-key/ that generates the secret key pair
3. To create a new test account, you need to enter the public key just now. The account name is a combination of 1-5 bits in length.
Create the address https://monitor.jungletestnet.io/#account of the test account
4. Recharge. If you have no money after the account is successfully established, you can recharge 100 yuan first. Save it when testing.
Top-up address http://monitor.jungletestnet.io/#faucet
5. After the account on the test chain is established, open the scatter--- identity-New, select the network = > jungle2 you just created, and then select the corresponding account. Point Import-Savin
So the scatter plug-in is configured. It can be developed happily.
Create scatter
ScatterJS.scatter.connect ("app") .then ((connected) = > {if (! connected) return false; let scatter = ScatterJS.scatter; / / here is window.ScatterJS = null; window.scatter = null; / / get the eos object / / this.eos = Eos ({httpEndpoint:', signatureProvider: ScatterJS.scatter.eosHook (jungle2)}); this.eos = scatter.eos (jungle2, Eos, {expireInSeconds: 60}) / / if the authorization is successful, you can get the user-related information if (scatter.identity) {this.account = scatter.identity.accounts.find ((x) = > x.blockchain = = "eos");}})
Authorization and de-authorization
/ authorized const requiredFields = {accounts: [jungle2]}; scatter .getIdentity (requiredFields) .then () = > {/ / get the user information and the eos object this.account = scatter.identity.accounts.find ((x) = > x.blockchain = "eos"); this.eos = scatter.eos (jungle2, Eos, {expireInSeconds: 60}, "https");}) .catch ((res) = > {}) / / exit scatter.forgetIdentity () .then ((id) = > {this.account = null; this.eos = null;})
Transfer transaction part
/ / currency related information let config = {account: "xxx", / / account name code: "eosio.token", / / contract name symbol: "ETH", / / currency}; eos.getCurrencyBalance (config). Then ((e) = > {console.log (e);}) / / fetch user-related information eos.getAccount ({account_name: "xxx"}) .then ((res) = > {/ / console.log (res) let totoal = res.core_liquid_balance; / / balance let cpu = res.cpu_limit; / / CPU let net = res.net_limit; / / NET}) / / initiate transfer / / eos.transfer ('sender account', 'receiver account', '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 means the transfer was successful}) .catch ((res) = > {}); / / you can also use object eos.transfer ({from: "sender account", to: "receiver account", quantity: "0.1000 account", memo: "remarks", callback,})
Interactive part
/ / get Table row data eosjs.getTableRows ({"scope": 'contract name', "code": 'contract name', "table": "game", "json": true}, callback) / / execute the function eos.contract ("contract name") on the contract. Then (actions = > {/ / actions random variable name actions.test ('hello', {/ / test is the method name) 'hello' is the parameter of the actions contract test method authorization: [{actor:'lilei'}] / / lilei is the user who created the contract}) .then (result = > {console.log (result)) }). The above is all the contents of the article "how to use scatter, the front-end plug-in for grapefruit wallets based on blockchain". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!