Metamask: Ethers npm metamask differentiate ropsten and mainnet

Metamask: Ethers NPM – Fay Mainnet and Ropsten

In Ethereum World Two Block Running on the Versh Bibliate Ethers.js: Mainnet and Ropsten. Each has its unique characteristic and the present -ending of the renewed deentalized attachments (DAPPS).

Mainnet Anti Ropsten: Display in Key

* Time block

: Time Mainnet block is 15 seconds, and Ropsten – 10 seconds.

* Translation fee : transaction fee at Ropsten in the Cash of the Less Promoter and Better Time Cabbot Transaction.

Ethers NPM and Metamask: Enable Consigns

DAPS DAPPS DAPPS DUPS DUPCHY HAPPY ENTER ETHERS.JS. Here’s how you can do this, use Metamask:

Metamask: Ethers npm metamask differentiate ropsten and mainnet

Shag 1: Install Metamask

Turned up your Metamask in the Ethereum Network:

`Bash

NPM Install Metamask

`

Passes Metamask in Ethers.js and Initialize it:

`Javascript

Const {web3} = need to ('@metamask/web3');

Const Web3 = New Web3 (New Web3.providers.httpprovider ('

const metamask = new web3.eth.wallet ("Your_metamask_public_key");

Shag 2: Check the network connection

Check the network connection before the transaction of the transaction:

`Javascript

IF (! Metamask.isconnected ()) {

Console.error ('Metamask is not connected.

}

Shag 3: Turn the payment

To include the plates, you need to realize that only the policies, which are confirmed on Mainnet, can pay with help metamask:

`Javascript

Ashron function MakePayment () {

Ask {

Const User = Waiting Metamask.getBalance ();

If (! User ||! Jewish Metamask.confirm ()) {

Console.error ('' The policeman did not confuse the crop, confuse the healer. ');

Recruit;

}

// Production Logiki Platage here ...

} Catch (error) {

Console.error (Oshbak);

}

}

Shag 4: Designion in the database

In the database you can use the catalog, such as ethers.js, if the voit in your plate: or unique resolution:

`Javascript

Ashron function MakePayment () {

Ask {

Const User = Waiting Metamask.getBalance ();

If (! POLUTER ||! Dodge Metamask.confirm ()) {

Console.error ('' The policeman did not confuse the crop, confuse the healer. ');

Recruit;

}

// Production Logiki Platage here ...

// Entry into the database

In db.collection ("Platters"). Insertone ({{

Userid: User.address,

TRANSECTIONHASH: 'Your_transction_hash',

Time Time: New Date (),

});

} Catch (error) {

Console.error (Oshbak);

}

}

The following is a shague, you can calculate Mainnet and Ropsten in Ethers.js, allowed after the policeman to make a salary without the submission of the statement on Metamask.

Dejar un comentario

Tu dirección de correo electrónico no será publicada.