Metamask: Ethers npm metamask differentiate ropsten and mainnet

Metamask: Ethers npm metamask differentiate ropsten and mainnet

METAAMAM: NPM ethers – differentiating between Mainnet and Ropsten

In the world to Ethereum, there are the twos in which you are executed are to the Ethers.js: Go and Ropsten library. Each has their characteristics, and understanding how to have a different between theme cruciial to bildering solid decentered applications (DAPP).

Go vs Ropsten: Key differentiation

* Block Time : The block time in Mainnet is 15 seconds, while in Ropsten their 10 seconds.

* Transaction rates : Transaction rates of looker in Ropsten due to its instant blocks and faster transaction in processing times.

NPM and Metamk ether: Allowing pay

When developing DAPPs with Ethers.js, you will be need to differentiate between the two Mainchans. This is is how you can achieve this using MetamSk:

Step 1: Install MetamSk

First, install the metamask wall on your Ethereum network:

`Bash

NPM Instama


Then, the Metahamk Amont in Its Ethers.js and Indigenous Code:

JavaScript

const {web3} = require ('@metamask/web3');

const web3 = new web3 (new web3.providers.httpProvider ('

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

Step 2: Check the Network Connection

Before Making Any Transaction, Check The Network Connection:

JavaScript

if (! MetamSk.isconnected ()) {

Console.error ( 'MetamSk no connected. Connect first');

}



Step 3: Allow Payment

To all-allow Payments, you shuold that's on-those only wesers who hass to be confirmed in.

JavaScript

Async Function Makepayment () {

attampt {

Const zer = ale metamask.getbalance ();

if (! Secret ||

Console.error.

return;

}

// Make Payment logic here ...

} capt (error) {

Console.error (arror);

}

}

Step 4: Registration Record in the data base

To record the pay in your data base, you can do a library as personaliced ​​solution:

JavaScript

Async Function Makepayment () {

attampt {

Const zer = ale metamask.getbalance ();

if (! Secret ||

Console.error.

return;

}

// Make Payment logic here ...

// record the pay in the data base

Wait dB.Collection ('payments'). insertone ({{

User: Seer.address,

Transactionah: 'Your_transaction_hash',

Time brand: new date ( ),

});

} capt (error) {

Console.error (arror);

}

}

Following these steps, you can have differential between Main and Ropsten in their Ethers.js application, which allows users in the registration of registration them in Metamk.

ETHEREUM HISTORICAL DATA

Share:

Leave comment

Marrakech 40000

160, Angle Avenue Mohamed V, Rue de la Liberté.

05 24 43 74 54

Appelez-nous aujourd'hui!

Heures d'ouverture

Lun - Ven : 8h30 - 12h30 / 15h00 - 19h00 Samedi : 8h30 - 13h00

Prenez rendez-vous

contact@drbichra.com