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

# Integrate Embedded Wallets with the Starknet Blockchain

While using the Embedded Wallets Web SDK (formerly Web3Auth) for a non-EVM chain like [Starknet](https://starkware.co/starknet/), 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`, `sign transaction`, `send transaction`, `read` from and `write` to the smart contract, etc. We have highlighted a few methods here to get you started quickly.

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

**npm**

```bash
npm install --save @web3auth/modal web3 starknet elliptic bn.js @starkware-industries/starkware-crypto-utils

```

**Yarn**

```bash
yarn add @web3auth/modal web3 starknet elliptic bn.js @starkware-industries/starkware-crypto-utils

```

**pnpm**

```bash
pnpm add @web3auth/modal web3 starknet elliptic bn.js @starkware-industries/starkware-crypto-utils

```

**Bun**

```bash
bun add @web3auth/modal web3 starknet elliptic bn.js @starkware-industries/starkware-crypto-utils

```

## 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/).

```tsx
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

### Getting the `chainConfig`

**Mainnet**

- Chain Namespace: other
- Chain ID: 0x1
- Public RPC URL: `https://rpc.ethereum.org` (Avoid using public rpcTarget in production)
- Display Name: Starknet Mainnet
- Block Explorer Link: `https://explorer.immutable.com`
- Ticker: STRK
- Ticker Name: Starknet

**Testnet**

- Chain Namespace: other
- Chain ID: 0xaa36a7
- Public RPC URL: `https://ethereum-sepolia.publicnode.com` (Avoid using public rpcTarget in production)
- Display Name: Starknet Testnet
- Block Explorer Link: `https://sepolia.etherscan.io`
- Ticker: STRK
- Ticker Name: Starknet

## Get account and Key

Once a user logs in, the Embedded Wallets SDK returns a provider. Even though Starknet is a layer 2 on Ethereum, it is not EVM compatible. Therefore, you cannot use the native [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) provider used for EVM blockchains; instead, use the private key directly to make calls.

Using the function, `web3auth.connection?.ethereumProvider?.request({ method: 'private_key' })` from Web3Auth provider, the application can have access to the user's private key. However, we cannot use this key with Starknet EC Curve specific signing functions, hence, we first derive the Stark Key using the `getStarkKey()` function.

Under the hood, it uses the `starkwareCrypto.ec.keyFromPrivate()` function, where we pass our Private key with the `hex` argument since it is hex encoded. Further, we get the public key from this using the `starkwareCrypto.ec.keyFromPublic()` function, and we take its X-coordinate using `.pub.getX()` which is our `starkKey`. We use this `starkKey` on Starknet transactions.

For the `deployAccount()`, we use the file `ArgentAccount.json` which gives us the ABI of the compiled contract. We use that contract in Starknet's `defaultProvider.deployContract()` function to deploy the contract.

[Get ArgentAccount.json from this gist.](https://gist.githubusercontent.com/yashovardhan/27e622a0f8de5acb3686674cd10fe0c8/raw/c1b2f70996083d2c3e85330464f71735aecf58a8/ArgentAccount.json)

```tsx
import starkwareCrypto from '@starkware-industries/starkware-crypto-utils'
import { ec as elliptic } from 'elliptic'
/*
  Use code from the above Initializing Provider here
*/

// web3authProvider is web3auth.connection?.ethereumProvider from above
const privateKey = await web3authProvider.request({ method: 'private_key' })
const keyPair = starkwareCrypto.ec.keyFromPrivate(privateKey, 'hex')
// get the account address from the public key
const account = starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true, 'hex'), 'hex')

// Use this key for the Starknet transactions
const startKey = account.pub.getX().toString('hex')

```

## Deploy an account

```tsx
import { AddTransactionResponse, defaultProvider } from 'starknet'
import starkwareCrypto from '@starkware-industries/starkware-crypto-utils'
import { ec as elliptic } from 'elliptic'
import CompiledAccountContractAbi from './ArgentAccount.json'
/*
  Use code from the above Initializing Provider here
*/

// web3authProvider is web3auth.connection?.ethereumProvider from above
const privateKey = await web3authProvider.request({ method: 'private_key' })
const keyPair = starkwareCrypto.ec.keyFromPrivate(privateKey, 'hex')
// get the account address from the public key
const account = starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true, 'hex'), 'hex')

const contract = JSON.parse(JSON.stringify(CompiledAccountContractAbi))
const response = await defaultProvider.deployContract({ contract })

```
