Table of Contents
Based on blockchain EOS wallet front-end plug-in scatter installation and use
Home Web Front-end JS Tutorial A brief analysis of the development of the EOS blockchain grapefruit wallet front-end plug-in scatter (share)

A brief analysis of the development of the EOS blockchain grapefruit wallet front-end plug-in scatter (share)

Sep 14, 2021 am 11:34 AM
js front end

In the previous article "Teach you how to use iis to deploy and run node in Node.js (with code)", I will introduce to you how to use iis to deploy and run node. The following article will introduce you to the development of the EOS blockchain grapefruit wallet front-end plug-in scatter. Let’s take a look.

A brief analysis of the development of the EOS blockchain grapefruit wallet front-end plug-in scatter (share)

Based on blockchain EOS wallet front-end plug-in scatter installation and use

Installation and use

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());
Copy after login

Network chain

// EOS公链(正式环境)
let main = {
  protocol: "https",
  blockchain: "eos",
  host: "nodes.get-scatter.com",
  port: 443,
  chainId: "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
};

// 测试链 (就是用来测试的)
let jungle2 = {
  protocol: "http",
  blockchain: "eos",
  host: "jungle2.cryptolions.io",
  port: 80,
  chainId: "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473",
};
Copy after login

Debugging and configuration

Download over the wallscatterPlug-in installation .

1. Open scatter---setting--network---create a new one and fill in the information of jungle2 Go to the corresponding location, (name it as you like, jungle2)--Save

2. Generate a secret key pair, generate private key and public key with one click

The address to generate the secret key pair https://eostea.github.io/eos-generate-key/

3. To create a new test account, you need to fill in the public key just now. The account name is z-a,1-512-digit combination

The address of the new test account https://monitor.jungletestnet.io/#account

4. Recharge. If you have no money after the account is successfully established, you can recharge 100 yuan first. When testing, be careful to use the

recharge address http://monitor.jungletestnet.io/#faucet

5. After the account on the test chain is established , open scatter---Identity---New, select the network => jungle2 just created, and then select the corresponding account. Click Import---Save

The scatter plug-in configuration is completed. You can develop happily.

Create scatter

ScatterJS.scatter.connect("app").then((connected) => {
  if (!connected) return false;
  let scatter = ScatterJS.scatter; //这里就是
  window.ScatterJS = null;
  window.scatter = null;
  //通过两种方式拿到eos 对象
  // this.eos = Eos({ httpEndpoint: '', signatureProvider: ScatterJS.scatter.eosHook(jungle2) });
  this.eos = scatter.eos(jungle2, Eos, { expireInSeconds: 60 });
  //如果授权成功,则可以拿到用户相关信息
  if (scatter.identity) {
    this.account = scatter.identity.accounts.find(
      (x) => x.blockchain === "eos"
    );
  }
});
Copy after login

Authorization and deauthorization

//授权
const requiredFields = { accounts: [jungle2] };

scatter
  .getIdentity(requiredFields)
  .then(() => {
    //分别拿到用户信息 和 eos 对象
    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;
});
Copy after login

Transfer transaction part

//取币种相关信息
let config = {
  account: "xxx", //账号名称
  code: "eosio.token", //合约名称
  symbol: "ETH", //币种
};
eos.getCurrencyBalance(config).then((e) => {
  console.log(e);
});

//取用户相关信息
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
});

//发起转账
// eos.transfer('发送方帐号', '接收方帐号', '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 就代表转账成功了
  })
  .catch((res) => {});

//还可以使用对象
eos.transfer({
  from: "发送方帐号",
  to: "接收方帐号",
  quantity: "0.1000 DEV",
  memo: "备注",
  callback,
});
Copy after login

Interactive part

// 获取Table行数据
eosjs.getTableRows({"scope":'合约名字', "code":'合约名字', "table":"game", "json": true},callback)

//执行合约上的函数

eos.contract("合约名字").then(actions => {       //actions随便起的变量名
    actions.test('hello', {                     //test是方法名, 'hello'是该actions合约test方法的参数
    	authorization: [{actor:'lilei'}]           //lilei是建立该合约的用户
    }).then(result => {
        console.log(result);
    });
Copy after login

Of course, there are many addresses for EOS API: https://developers.eos.io/eosio-nodeos/ v1.6.0/reference#get_block But for the front end, the above is enough to develop an online gambling game.

As for issuing tokens, deploying contracts, staking, bidding, selling, buying, and creating new accounts are not needed and can be transferred to the backend.

【End】

Recommended learning: JS video tutorial

The above is the detailed content of A brief analysis of the development of the EOS blockchain grapefruit wallet front-end plug-in scatter (share). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

PHP and Vue: a perfect pairing of front-end development tools PHP and Vue: a perfect pairing of front-end development tools Mar 16, 2024 pm 12:09 PM

PHP and Vue: a perfect pairing of front-end development tools. In today's era of rapid development of the Internet, front-end development has become increasingly important. As users have higher and higher requirements for the experience of websites and applications, front-end developers need to use more efficient and flexible tools to create responsive and interactive interfaces. As two important technologies in the field of front-end development, PHP and Vue.js can be regarded as perfect tools when paired together. This article will explore the combination of PHP and Vue, as well as detailed code examples to help readers better understand and apply these two

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

C# development experience sharing: front-end and back-end collaborative development skills C# development experience sharing: front-end and back-end collaborative development skills Nov 23, 2023 am 10:13 AM

As a C# developer, our development work usually includes front-end and back-end development. As technology develops and the complexity of projects increases, the collaborative development of front-end and back-end has become more and more important and complex. This article will share some front-end and back-end collaborative development techniques to help C# developers complete development work more efficiently. After determining the interface specifications, collaborative development of the front-end and back-end is inseparable from the interaction of API interfaces. To ensure the smooth progress of front-end and back-end collaborative development, the most important thing is to define good interface specifications. Interface specification involves the name of the interface

Questions frequently asked by front-end interviewers Questions frequently asked by front-end interviewers Mar 19, 2024 pm 02:24 PM

In front-end development interviews, common questions cover a wide range of topics, including HTML/CSS basics, JavaScript basics, frameworks and libraries, project experience, algorithms and data structures, performance optimization, cross-domain requests, front-end engineering, design patterns, and new technologies and trends. . Interviewer questions are designed to assess the candidate's technical skills, project experience, and understanding of industry trends. Therefore, candidates should be fully prepared in these areas to demonstrate their abilities and expertise.

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

See all articles