> ## Documentation Index
> Fetch the complete documentation index at: https://docs.near.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Hello Ethereum Wallets!

> You can now login using MetaMask, WalletConnect and +400 Ethereum Wallets on Near!

***Guille, Slava Karkunov** · November 7, 2024*

*You can now login using MetaMask, WalletConnect and +400 Ethereum Wallets on Near!*

<p>
  <img src="https://mintcdn.com/neardocs/RuYMAM7eln2T5AA7/assets/blog/web3wallets/cover.png?fit=max&auto=format&n=RuYMAM7eln2T5AA7&q=85&s=550a74978421679f3e19e7f40c6c79bf" width="2812" height="1166" data-path="assets/blog/web3wallets/cover.png" />
</p>

## Ethereum Wallets on NEAR

We are excited to announce that NEAR now supports Ethereum wallets! This means that you can now login to NEAR applications using MetaMask, WalletConnect, and over 400 other Ethereum wallets.

In this post, we will explain how Ethereum wallets work on NEAR, and where to find information on how to integrate them into your applications.

## How it works

The idea of bringing Ethereum wallets to Near was born on the [NEP-518](https://github.com/near/NEPs/issues/518), and the [Aurora Labs team](https://aurora.dev) worked for over a year to make it a reality.

Since Ethereum wallets create **ethereum transactions** and talk with **ethereum RPCs**, the Aurora team had to create three components:

1. A `Transaction Encoder` service, that encodes NEAR actions into Ethereum transactions
2. A `Translator RPC` service, that translates Ethereum RPC calls into NEAR RPC calls
3. A `Wallet Contract` that allows NEAR accounts to process EVM transactions

<img src="https://mintcdn.com/neardocs/RuYMAM7eln2T5AA7/assets/blog/web3wallets/diagram.png?fit=max&auto=format&n=RuYMAM7eln2T5AA7&q=85&s=99a18cd50609e21572b4098f16a5321f" height="600px" style={{width: "auto", display: "block", margin: "0 auto"}} data-path="assets/blog/web3wallets/diagram.png" />

***

### Transaction Encoder

The `Transaction Encoder` - implemented [directly in the NEAR Wallet Selector](https://github.com/near/wallet-selector/blob/main/packages/ethereum-wallets/src/lib/index.ts) - takes the intent of the user (e.g. call `set_greeting` on `hello.near`) and translates it into an Ethereum transaction that the EVM wallet can sign.

#### To (field)

The `to` field of the Ethereum transaction is transformed following these rules:

* If the `receiverId` matches `^0x[a-f0-9]{40}$` (e.g. `0xD79...314`), then the `to` field is set to the `receiverId`
* Otherwise (e.g. `ana.near` or an implicit account) the `to` field is set as `keccak-256(receiverId)[12,32]`

#### Data (field)

The `data` field contains the RLP-encoded NEAR actions wanted by the user, encoded as function calls on Ethereum, for example:

* `FunctionCall(to: string, method: string, args: bytes, yoctoNear: uint32)`
* `Transfer(to: string, yoctoNear: uint32)`
* `Stake(public_key: bytes, yoctoNear: uint32)`
* `AddKey(public_key: bytes, nonce: uint64, is_full_access: bool, allowance: uint256, receiver_id: string, method_names: string[])`

<Info>
  For more information on how other fields (such as `value`, `gas`, and `chainId`) are set, please refer to the [NEP-518 technical specification](https://github.com/near/NEPs/issues/518)
</Info>

***

### Translator RPC

The `Translator RPC` is a service deployed at `https://eth-rpc.mainnet.near.org` (for mainnet) and `https://eth-rpc.testnet.near.org` (for testnet) that translates Ethereum RPC calls into NEAR RPC calls.

In other words, the `Translator RPC` simply acts as a relayer, taking the Ethereum transactions signed by the user and translating them into a function call into the `Wallet Contract` deployed in the user's account.

***

### Wallet Contract

The `Wallet Contract` is a smart contract on NEAR that allows NEAR accounts to process EVM transactions.

The contract exposes a method called `rlp_execute`, which takes as argument an RLP-encoded Ethereum transaction, verifies its signature, and executes the NEAR actions encoded in the `data` field of the transaction.

Every NEAR account created through an EVM wallet has the `Wallet Contract` deployed on it.

<Tip>
  Remember that in NEAR **all accounts** can **have contracts**, and that **contracts** can perform **all the actions** that the **account can do**.
</Tip>

***

## Using the Account

### First Time Login

Imagine your account on Metamask is `0xD79...314`, and you want to login on a Near application.

The first time you login through your EVM wallet, the wallet selector will contact the account `ethereum-wallets.near` to create a NEAR account with the same address as your Ethereum wallet. For example, if your address on Metamask is `0xD79...314`, the NEAR account created will be `0xD79...314`.

On this account, the `Wallet Contract` is deployed and a function-call key is added for the `rlp_execute` function of the contract.

<img src="https://mintcdn.com/neardocs/RuYMAM7eln2T5AA7/assets/blog/web3wallets/login.png?fit=max&auto=format&n=RuYMAM7eln2T5AA7&q=85&s=56bb2a7e2e1dd6d3884b3fa86f8b2adf" style={{width: "auto", display: "block", margin: "0 auto"}} width="1654" height="798" data-path="assets/blog/web3wallets/login.png" />

### Interacting with Applications

Once you have logged in, you can start interacting with the application. If at some point the application needs to interact with the blockchain, Metamask will ask you to sign a transaction.

Under the hood, Metamask will create an Ethereum transaction and send it to the `Translator API`, deployed at `https://eth-rpc.mainnet.near.org`.

The `Translator API` will then translate the Ethereum transaction into a **function call** into the `Wallet Contract` deployed in your account. Particularly, it will call the `rlp_execute` function, passing the Ethereum transaction as an argument.

<img src="https://mintcdn.com/neardocs/RuYMAM7eln2T5AA7/assets/blog/web3wallets/function-call.png?fit=max&auto=format&n=RuYMAM7eln2T5AA7&q=85&s=b9056d52249694e897492a3724302801" style={{width: "auto", display: "block", margin: "0 auto"}} width="1686" height="853" data-path="assets/blog/web3wallets/function-call.png" />

The `Wallet Contract` will then execute the function call, and the application will receive the result.

<Tip>
  Check [this transaction](https://testnet.nearblocks.io/txns/GrVGFVFmGBcNP5xkoA21gEJ7d5bUGVxtmkfHAzyUW895#enhanced) in our explorer to see the full execution path
</Tip>

## Updating your Application

In order to support Ethereum wallets, you only need to update your version of `wallet-selector`, and configure it to include the new `ethereum-wallets` module.

Do not worry! it is very simple, check the working example [**hello world frontend**](https://github.com/near-examples/hello-near-examples/tree/main/frontend).

***

## Resources

1. [Hello World Example](https://github.com/near-examples/hello-near-examples/blob/main/frontend/)

2. [Recording of the Ethereum Wallet Presentation](https://drive.google.com/file/d/1xGWN1yRLzFmRn1e29kbSiO2W1JsxuJH-/view?usp=sharing)

3. [NEP-518](https://github.com/near/NEPs/issues/518), the proposal that started it all
