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

# Integrate Embedded Wallets with the Klaytn Blockchain in Node

While using the Embedded Wallets Node.js SDK, you get a viem WalletClient on successful authentication. This signer can be used with [viem](https://viem.sh/) to make [Klaytn](https://ethereum.org/) blockchain calls like getting the user's account, fetching balance, signing transactions, sending transactions, reading from and writing to smart contracts, etc.

## Chain details for Klaytn[​](#chain-details-for-klaytn "Direct link to Chain details for Klaytn")

- Mainnet
- Baobab Testnet

- **Chain ID:** 0x2019
- **Public RPC URL:** `https://public-node-api.klaytnapi.com/v1/cypress`
- **Display Name:** Klaytn Mainnet
- **Block Explorer Link:** `https://scope.klaytn.com`
- **Ticker:** KLAY
- **Ticker Name:** Klaytn

- **Chain ID:** 0x3e9
- **Public RPC URL:** `https://api.baobab.klaytn.net:8651`
- **Display Name:** Klaytn Baobab Testnet
- **Block Explorer Link:** `https://baobab.scope.klaytn.com`
- **Ticker:** KLAY
- **Ticker Name:** Klaytn

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

To interact with the blockchain, use the [viem](https://viem.sh/) library with the `WalletClient`returned by `connect()`.

- npm
- Yarn
- pnpm
- Bun

```
npm install --save viem

```

```
yarn add viem

```

```
pnpm add viem

```

```
bun add viem

```

## Initialize[​](#initialize "Direct link to Initialize")

```
const { Web3Auth } = require('@web3auth/node-sdk')

const web3auth = new Web3Auth({
  clientId: 'YOUR_WEB3AUTH_CLIENT_ID', // Pass your Web3Auth Client ID, ideally using an environment variable
  web3AuthNetwork: 'sapphire_mainnet', // or 'sapphire_devnet'
})

await web3auth.init()

const result = await web3auth.connect({
  authConnectionId: 'YOUR_AUTH_CONNECTION_ID', // Your custom authentication connection name
  idToken: 'USER_ID_TOKEN', // JWT token from your auth system
})

```

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

```
// Get user's Ethereum public address
const address = result.signer.account.address
console.log('\x1b[33m%s\x1b[0m', 'Accounts:', address)

```

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

```
const { createPublicClient, formatEther, http } = require('viem')

const address = result.signer.account.address
const publicClient = createPublicClient({
  chain: result.signer.chain,
  transport: http(),
})
const balance = formatEther(await publicClient.getBalance({ address }))
console.log('\x1b[33m%s\x1b[0m', 'Balance:', balance, 'ETH')

```

## Sign a message[​](#sign-a-message "Direct link to Sign a message")

```
const signature = await result.signer.signMessage({ message })
console.log('\x1b[33m%s\x1b[0m', 'Signed Message:', signature)

```
