In this doc, dapp developers can learn about the integration of MetaMask into their Rangers Protocol dapp with web3.js.
MetaMask is an open source Ethereum wallet that helps users easily manage their digital assets.In addition, it can help test smart contract functions, support most Dapps, be compatible with hardware wallets, and send coins with one click.
MetaMask holds a dialogue with Web3 RPC or API on the Rangers Protocol node, and the MetaMask connection is based on a similar Ethereum function, it is possible to reconfigure MetaMask in a way similar to Ethereum. That is, in the settings of MetaMask, you can access a node based on the Rangers Protocol by adding a new network.
web3.js config
Step 1 Install web3
In order to better serve the dapps on Rangers Protocol, it is recommended that you install web3 under your DApp. Learn how to add web3.js into your dapp here.
npm install web3 --save
Step 2 Web3 Call
Create a new file named “web3.js” and paste the following code into it
The web3 instance in the above code requests access to the MetaMask account by detecting a global object (ethereum or web3) injected by MetaMask. According to the : MetaMask injects a global API into websites visited by its users at window.ethereum. This API allows websites to request users' Ethereum accounts, read data from blockchains the user is connected to, and suggest that the user sign messages and transactions. The presence of the provider object indicates an Ethereum user. In simple terms, it can help instantiate our web3 object.
Metamask provides plug-in functions that can be used in the browser, which greatly frees up your computer memory. It supports chrome, firefox, edge and Brave. The following will use chrome as a tutorial. In the chrome web store, search for MetaMask in the
The necessary step of sending transaction is to add the Rangers Protocol into the MetaMask, and the detailed demonstration would be helpful when in practice.