Skip to content

Commit

Permalink
[EVM] Add Wallets & Configruations (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Feb 27, 2024
1 parent 3176d76 commit 9947751
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Binary file added docs/evm/Build/metamask-network.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions docs/evm/Build/wallets-and-configurations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: Wallets & Configurations
sidebar_label: Wallets & Configurations
sidebar_position: 4
---

# Wallets & Configurations

This document shows how to integrate the FlowEVM Network programmatically with your Dapp via MetaMask.

## Metamask

Integrating additional networks into MetaMask can pose challenges for users who lack technical expertise and may lead to errors. Simplifying this process can greatly enhance user onboarding for your application. This guide demonstrates how to create a straightforward button within your frontend application to streamline the addition of the Berachain network to MetaMask.

### EIP-3035 & MetaMask

[EIP-3035](https://eips.ethereum.org/EIPS/eip-3085) is an Ethereum Improvement Proposal that defines an RPC method for adding Ethereum-compatible chains to wallet applications. Since March 2021 MetaMask has implemented that EIP as part of their MetaMask [Custom Networks API](https://consensys.io/blog/connect-users-to-layer-2-networks-with-the-metamask-custom-networks-api).

### Network configuration

To add the FlowEVM network to Metamask, we need to add the following network confgiuration:

#### Previewnet Network

```js
export const FLOWEVM_PREVIEWNET_PARAMS = {
chainId: '0x286',
chainName: 'Flow',
rpcUrls: ['https://previewnet.evm.nodes.onflow.org'],
nativeCurrency: {
name: 'Flow',
symbol: 'FLOW',
decimals: 18,
},
blockExplorerUrls: ['https://previewnet.flowdiver.io'],
}
```

### Adding the Network

To add this configuration to MetaMask, we must call the `wallet_addEthereumChain` method which is exposed by the web3 provider.

```js
function addFlowEvmNetwork() {
injected.getProvider().then((provider) => {
provider
.request({
method: "wallet_addEthereumChain",
params: [FLOWEVM_PREVIEWNET_PARAMS],
})
.catch((error: any) => {
console.log(error)
})
})
}
```

The variable, `injected`, is initialized as a `web3-react/injected-connector` used to interface with MetaMask APIs. Usage for other popular web frameworks is similar.

The typical usage would be to expose this button if you get errors when attempting to connect to MetaMask (i.e. `Wrong Network` or `Error Connecting`).

### User Experience

Users who first come to your dApp's website will need to first approve a connection to Metamask. After doing this, if you don't detect a successful Web3 network connection, you may present a dialog asking them to add the FlowEVM network to their wallet.

![Metamask Network](./metamask-network.png)

After they approve, your app be connected to the FlowEVM network.

By using this approach to add the FlowEVM network to Metamask, you can avoid manual user data entry and ensure that users are ready to interact with your dApp!

0 comments on commit 9947751

Please sign in to comment.