Sign in with Ethereum Web3 Wallet
Introduction
In this guide, you will examine what a web3 wallet is, how to sign in to your wallet, and how to use the popular wallet MetaMask. We will learn to log in to your Metamask wallet using Refine and Web3.
A web3 wallet is a software that allows you to send, receive, or store cryptocurrency securely without the need for a 3rd party. Web3 wallet is your key to accessing your cryptocurrency. If you want to send cryptocurrency or receive it you will need a wallet.
We will show you how to log in to your Metamask wallet with Refine.
Installation
We will need web3 and web3-modal packages in our project. Let's start by downloading these packages.
- npm
- pnpm
- yarn
npm i web3 web3modal
pnpm add web3 web3modal
yarn add web3 web3modal
CAUTION
To make this example more visual, we used the @refinedev/antd package. If you are using Refine headless, you need to provide the components, hooks or helpers imported from the @refinedev/antd package.
Configure Refine Auth provider
First, we need to define a web3modal and create a provider. We can get information about the wallet by connecting this provider that we have created to web3.
NOTE
In this example, we will show the login with Metamask Wallet. If you want, you can connect to other wallets using web3modal's providers.
Show Code
We use web3's getBalance() function to find out the ethereum amount of the account logged in.
const web3 = new Web3(window.ethereum);
export const getBalance = async (account: string): Promise<string> => {
return new Promise((resolve, reject) => {
web3.eth.getBalance(account, (err: any, result: any) => {
if (err) {
reject(err);
} else {
resolve(web3.utils.fromWei(result, "ether"));
}
});
});
};
Override Login page
We need to override the Refine login page. In this way, we will redirect it to the Metamask Wallet login page. We create a login.tsx file in the /pages folder.
Show Code

Create Dashboard
After connecting with our account, we can now retrieve account information. We will display this information on the dashboard of the Refine.
Show Code

Now lets customize Refine dashboard. Send your test ethereum via Refine dashboard and Metamask.
Send Test Ethereum with Refine Dashboard
Here we use the sendTransaction function to send ethereum with your browser-enabled web3 wallet.
export const sendEthereum = async (
sender: string,
receiver: string,
amount: string,
) => {
try {
const params = {
from: sender,
to: receiver,
value: web3.utils.toHex(web3.utils.toWei(amount, "ether")),
gas: 39000,
};
await window.ethereum.enable();
return await web3.eth.sendTransaction(params);
} catch (error) {
new Error("Something went wrong!");
}
};
Show Code

We can now request to send ethereum through our Refine dashboard and also view your account details on Etherscan Ropsten Test Network

Example
npm create refine-app@latest -- --example with-web3