> For the complete documentation index, see [llms.txt](/llms.txt).

# Integrate Embedded Wallets with the Near Blockchain

While using the Embedded Wallets Web SDK (formerly Web3Auth) for a non-EVM chain like [NEAR](https://near.org/), you can get the user's private key from the provider. Using this private key, you can use the corresponding libraries of the blockchain to make blockchain calls like getting a user's `account`, fetching `balance`, and performing `send transaction`. To help you get started, we've outlined some methods you can use.

note

The SDKs are now branded as MetaMask Embedded Wallet SDKs (formerly Web3Auth Plug and Play SDKs). Package names and APIs remain Web3Auth (for example, Web3Auth React SDK), and code snippets may reference `web3auth` identifiers.

## Installation[​](#installation "Direct link to Installation")

- npm
- Yarn
- pnpm
- Bun

```
npm install --save @web3auth/modal near-api-js@4.0.4

```

```
yarn add @web3auth/modal near-api-js@4.0.4

```

```
pnpm add @web3auth/modal near-api-js@4.0.4

```

```
bun add @web3auth/modal near-api-js@4.0.4

```

## Initialize Embedded Wallets[​](#initialize-embedded-wallets "Direct link to Initialize Embedded Wallets")

After v10, you don't need chain-specific setup in code for non-EVM chains. Configure standard EVM chains on the [Embedded Wallets dashboard](/embedded-wallets/dashboard/chains-and-networks/).

```
import { Web3Auth, WEB3AUTH_NETWORK } from '@web3auth/modal'

const web3auth = new Web3Auth({
  clientId,
  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
})

await web3auth.init()
await web3auth.connect()

const web3authProvider = web3auth.connection?.ethereumProvider ?? null

```

Non-EVM chains derive keys from `web3authProvider` using the `private_key` JSON-RPC method, as shown in the examples below.

## Initializing provider[​](#initializing-provider "Direct link to Initializing provider")

### Getting the `chainConfig`[​](#getting-the-chainconfig "Direct link to getting-the-chainconfig")

- Mainnet
- Testnet

- Chain Namespace: other
- Chain ID: 0x4e454152
- Public RPC URL: `https://mainnet.aurora.dev` (Avoid using public rpcTarget in production)
- Display Name: Near
- Block Explorer Link: `https://aurorascan.dev`
- Ticker: NEAR
- Ticker Name: NEAR

- Chain Namespace: other
- Chain ID: 0x4e454153
- Public RPC URL: `https://testnet.aurora.dev` (Avoid using public rpcTarget in production)
- Display Name: Near
- Block Explorer Link: `https://explorer.testnet.aurora.dev`
- Ticker: NEAR
- Ticker Name: NEAR

## Get keypair and account[​](#get-keypair-and-account "Direct link to Get keypair and account")

After a user logs in, they receive a provider from the Embedded Wallets SDK. However, there is no native provider for Near, so we use the private key to make RPC calls directly.

To access the user's private key, the application can use `web3auth.connection?.ethereumProvider?.request({ method: 'private_key' })`. Since Near requires `ed25519`, use `getED25519Key()` (from the same package set) to convert the `secp256k1` key to an `ed25519` key.

```
import { connect, KeyPair, keyStores, utils } from 'near-api-js'
import { getED25519Key, type IProvider } from '@web3auth/modal'
/*
  Use code from the above Initializing Provider here
*/

// web3authProvider is web3auth.connection?.ethereumProvider from above
const privateKey = await web3authProvider.request({ method: 'private_key' })

// Convert the secp256k1 key to ed25519 key
// When starting your application with "solana" namespace, you can skip the below two lines
// and pass the privateKey directly to buffer.
const privateKeyEd25519 = getED25519Key(privateKey).sk.toString('hex')

// Convert the private key to Buffer
const privateKeyEd25519Buffer = Buffer.from(privateKeyEd25519, 'hex')

// Convert the private key to base58
const bs58encode = utils.serialize.base_encode(privateKeyEd25519Buffer)

// Convert the base58 private key to KeyPair
const keyPair = KeyPair.fromString(`ed25519:${bs58encode}`)

// publicAddress
const publicAddress = keyPair?.getPublicKey().data || []

// accountId is the account address on Near which is where funds will be sent to.
const accountId = Buffer.from(pk58 || []).toString('hex')

```

## Get balance[​](#get-balance "Direct link to Get balance")

```
import { connect, keyStores, utils } from 'near-api-js'
/*
  Use code from the above Initializing Provider here
*/
const myKeyStore = new keyStores.InMemoryKeyStore()
await myKeyStore.setKey('testnet', accountId, keyPair) // accountId and keyPair from above
const connectionConfig = {
  networkId: 'testnet',
  keyStore: myKeyStore,
  nodeUrl: 'https://rpc.testnet.near.org',
  walletUrl: 'https://wallet.testnet.near.org',
  helperUrl: 'https://helper.testnet.near.org',
  explorerUrl: 'https://explorer.testnet.near.org',
}
const nearConnection = await connect(connectionConfig)
const account = await nearConnection.account(accountId)
const accountBalance = await account.getAccountBalance()
const availableBalance = utils.format.formatNearAmount(accountBalance.available)

```

## Send transaction[​](#send-transaction "Direct link to Send transaction")

```
import { connect, keyStores, utils } from 'near-api-js'
/*
  Use code from the above Initializing Provider here
*/
const receiver = 'shahbaz17.testnet'
const amount = '2' // in NEAR
const myKeyStore = new keyStores.InMemoryKeyStore()
await myKeyStore.setKey('testnet', accountId, keyPair) // accountId and keyPair from above
const connectionConfig = {
  networkId: 'testnet',
  keyStore: myKeyStore,
  nodeUrl: 'https://rpc.testnet.near.org',
  walletUrl: 'https://wallet.testnet.near.org',
  helperUrl: 'https://helper.testnet.near.org',
  explorerUrl: 'https://explorer.testnet.near.org',
}
const nearConnection = await connect(connectionConfig)
const senderAccount = await nearConnection.account(accountId)
const result = await senderAccount.sendMoney(receiver, utils.format.parseNearAmount(amount))

```
