# MetaMask

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&#x20;

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

```
 const web3 = new Web3(Web3.givenProvider || "<https://robin.rangersprotocol.com/api/jsonrpc>");


 export const contractDeploy = async (abi) => {
  let contract0Binary = '608060405234801561001057600080fd5b507f1f61fd9dd9c9696ab5bc318a94aa0b166e72294a1f6fb73fb544ef66dc92dd576040518080602001828103825260038152602001807f616263000000000000000000000000000000000000000000000000000000000081525060200191505060405180910390a1610316806100886000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630a8e8e011461005c5780631ad7be821461007a57806366e41cb71461010f5780636b59084d146101315780638f0d282d1461014f575b600080fd5b6100646101d2565b6040518082815260200191505060405180910390f35b6100826101db565b604051808481526020018060200183151515158152602001828103825284818151815260200191508051906020019080838360005b838110156100d25780820151818401526020810190506100b7565b50505050905090810190601f1680156100ff5780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b61011761022a565b604051808215151515815260200191505060405180910390f35b610139610263565b6040518082815260200191505060405180910390f35b6101576102a4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561019757808201518184015260208101905061017c565b50505050905090810190601f1680156101c45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000607b905090565b600060606000607b60018191506040518060400160405280600481526020017f617364660000000000000000000000000000000000000000000000000000000081525090925092509250909192565b6000600115157f80255c575434223f7207fd83b26cb59a897298231ad7ac818ae3495e741e4d4160405160405180910390a26001905090565b60007f8e117c8dc7842a9f68ac9c5b765eb834d357ef0d2d0b6a834e5e0613d29f3b836101c86040518082815260200191505060405180910390a142905090565b60606040518060400160405280600581526020017f313233343500000000000000000000000000000000000000000000000000000081525090509056fea265627a7a7231582070566f81f81535fc569d6931966a5d0f2539b5f2d0910c71f4b71fd14853ff7564736f6c63430005110032';
  let contract = new web3.eth.Contract(abi);
  try {
    const address = await web3.eth.accounts.wallet.add('f987bba2f33643549b1b621f0570724***cbae8ca750388c6edaca67a1ddd410');
    const newContractInstance = await contract
          .deploy({data: contract0Binary})
          .send({
              from: address.address,
              gasLimit:666000,
          }); 
    console.log(newContractInstance)
  } catch (error) {
    console.log(error);
  }
}
```

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 API Documentation](https://docs.metamask.io/guide/ethereum-provider.html#upcoming-provider-changes) : 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 Wallet Setup&#x20;

#### Set MetaMask on your browser&#x20;

* 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 [chrome web store](https://chrome.google.com/webstore/category/extensions)

![](https://lh5.googleusercontent.com/tSVuxwUdqvy0i1BwmXcJfVbCrp1PZS9a8xTiesbhDQNST8clqTBMUm3SeSBwgaEKnAHUMdq8x82gBSerFAIBpZtkFn-DYl5oHywnkCwEfjOO6bkWGZ6yQbixQZjKNXBUtPyIvIFS74XPeJLBtij-Uu8)



* click “add to chrome” , then MetaMask will be download automatically Create a wallet

![](https://lh6.googleusercontent.com/NZTZajJiA-IVb_r6Ak72kaVrK6nRO7H3r_NrTpH5FTKeACkjOf7aoiNvtQNxZEtqA60I8YvjSfp3l0-o82_smUvqEbpDDIjvGkljr3LcVbqF2mrFqFEDei630ze4kAvjYG-JtUFCcZOJwE5gaPdcy80)

* Create password

![](https://lh5.googleusercontent.com/SSq4W5gi6g-lQBNNI9dOPbXOyqaCpHYl1A2LWV8telkyClqsjBQapVL8o8_nX_s6JfWvYoVkKVsy3DvVjMsOkoXtxdOsuPqvNM3cBeMopNy7Tu4bxnbn6gqJ7ELB_BtQKGN-l_VofqLeCgrzvyY_ZV0)

* Secure your wallet, watch a video to learn how to keep your wallet safe.

![](https://lh4.googleusercontent.com/hJNmr-lgsezsORgdfwwY4-3JDMWXPdpTEO87e22PYPFC-kfB3UddY9g-_p2ZMXJOW6RKpvZV4E4MfEs__obfGJdfxiZqWcIObwXsmcWJ-tzWzfJ4LPcXLEMZXNUKXSAbXCxZaNm9GlVaw_opD2x6Rb0)

* Reveal and remember your secret recovery phrase

![](https://lh6.googleusercontent.com/5WA9wvgZbCQ3yFP2HwPqc1sVnHtOGkF_m8TzFr6-a1zR5uEQitlzbBOUldu9s7HFoQqJI8txDYo2u-n7-ITW2YGhpfgEM3GwEH_f1UkKEBzGn_x7aSgFcdhM5BYHxoiMFhGKR4y-44uGu2I5PDNXbzc)

* Test

![](https://lh6.googleusercontent.com/pJ2WkR_oOy-UgATx_qrzbb0-OkTT2UbjFfnA3zJkHlb7anY7ppi2rL8AfVG6u3gVCdsLTpKk9sbnqoc6VJt6Q44mUacICjRi-O1uzItQ9krBIKvDnZ40Jqwkvv72EwuD65CTylxO9eWPs9Vc7200DHg)

* Confirm and All done!

## Export private key&#x20;

* Enter the MetaMask homepage and click“Account details”

![](https://lh6.googleusercontent.com/5hJlfqFma6FLQ8-P63k9FFJcfycovfvioFZedZER85MoD4HBvWA_tvxnExTRX1XZ6WmFg-aCQR8o0Z1lbe2wbuXuvQ_cyCFsPz8Tt6M3LvBHJSY4ve72GjEcFyvmTUHKN4HRct5wW_sj0GuOC6TWCBo)

* **Export the private key**

![](https://lh3.googleusercontent.com/HjAUV77ZEMu5SIW1FqAYBdwK9utaVNpFo2j52G8Nkj3SsKfKSBZW900N19NAWHnwFVy2VT_8EEwfiGH5rs7D1PNooQHeFPr9EqTkBcL6Mo8ZvkU-y99Vm2brr9ZG2oOcvMqrMEH38TtJQtQXKtEFzIE)

* Enter your password and get private key

#### Add the Rangers Protocol into MetaMask

* The necessary step of sending transaction is to add the Rangers Protocol into the MetaMask, and the detailed demonstration [instructions](https://rangersprotocol.gitbook.io/technical-documentation/smart-contract/using-remix#a-demo-of-smart-contract-deployment-on-rangers-protocol) would be helpful when in practice.
