# \[Archive\] I want to integrate Solana chain with react native

**URL:** <https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841>\
**Category:** Embedded Wallets (Web3Auth)\
**Created:** [August 7, 2023, 6:32pm UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841 "2023-08-07T18:32:43Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![yammonabd](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yammonabd](https://builder.metamask.io/u/yammonabd)\
**Post date:** [August 7, 2023, 6:32pm UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/1 "2023-08-07T18:32:43Z")

</div>

> **🏛 Archived Content from Web3Auth Community**
> 
> This topic was originally posted by **yammonabd** on 8/7/2023.  
> This content has been migrated from our previous community forum to preserve valuable discussions.

* * *

I couldn’t find documentation, can anyone help with this?

- SDK Version: @web3auth/react-native-sdk": "^4.0.0
- Expo or Bare Version: 0.72.3

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [August 7, 2023, 11:59pm UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/2 "2023-08-07T23:59:47Z")

</div>

@yammonabd Thanks for your patience.

You may check out some examples below:

```
  <a href="https://github.com/Web3Auth/web3auth-pnp-examples/tree/main/web-modal-sdk/blockchain-connection-examples/solana-modal-example" target="_blank" rel="noopener">github.com</a>

```

### 

[//github.com/Web3Auth/web3auth-pnp-examples/tree/main/web-modal-sdk/blockchain-connection-examples/solana-modal-example](https://github.com/Web3Auth/web3auth-pnp-examples/tree/main/web-modal-sdk/blockchain-connection-examples/solana-modal-example)

```
  <a href="https://github.com/Web3Auth/web3auth-pnp-examples/tree/main/web-no-modal-sdk/blockchain-connection-examples/solana-no-modal-example" target="_blank" rel="noopener">github.com</a>

```

### 

[//github.com/Web3Auth/web3auth-pnp-examples/tree/main/web-no-modal-sdk/blockchain-connection-examples/solana-no-modal-example](https://github.com/Web3Auth/web3auth-pnp-examples/tree/main/web-no-modal-sdk/blockchain-connection-examples/solana-no-modal-example)

```
  <a href="https://github.com/Web3Auth/web3auth-pnp-examples/tree/main/react-native" target="_blank" rel="noopener">github.com</a>

```

### 

[//github.com/Web3Auth/web3auth-pnp-examples/tree/main/react-native](https://github.com/Web3Auth/web3auth-pnp-examples/tree/main/react-native)

---

<div class="post-metadata">

**Author:** ![yammonabd](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yammonabd](https://builder.metamask.io/u/yammonabd)\
**Post date:** [August 8, 2023, 8:26am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/3 "2023-08-08T08:26:01Z")

</div>

Thank you, but the examples for Solana are with react not react native.

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [August 8, 2023, 8:52am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/4 "2023-08-08T08:52:37Z")

</div>

Please refer to this [Integrate Web3Auth with the Solana Blockchain | Documentation | Web3Auth](https://web3auth.io/docs/connect-blockchain/solana)

This reference is for the `Web` , however, you can use Solana on `Android` , `iOS` , `React Native` , `Flutter` , & `Unity` as well. Please follow our reference for [Ethereum](https://web3auth.io/docs/connect-blockchain/ethereum/), and similarly use Solana libraries that support the platforms to use the private key and make blockchain calls accordingly.

---

<div class="post-metadata">

**Author:** ![yammonabd](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yammonabd](https://builder.metamask.io/u/yammonabd)\
**Post date:** [August 8, 2023, 9:09am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/5 "2023-08-08T09:09:28Z")

</div>

I’m unable to view this link [https://web3auth.io/docs/connect-blockchain/react-native](https://web3auth.io/docs/connect-blockchain/react-native)

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [August 8, 2023, 9:10am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/6 "2023-08-08T09:10:42Z")

</div>

The link does not exist , nor is it listed in our documentation.

---

<div class="post-metadata">

**Author:** ![yammonabd](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yammonabd](https://builder.metamask.io/u/yammonabd)\
**Post date:** [August 8, 2023, 9:12am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/7 "2023-08-08T09:12:57Z")

</div>

When I click the link you provided [Integrate Web3Auth with the Ethereum Blockchain | Documentation | Web3Auth](https://web3auth.io/docs/connect-blockchain/ethereum) and choose react native it shows

---

<div class="post-metadata">

**Author:** ![yammonabd](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yammonabd](https://builder.metamask.io/u/yammonabd)\
**Post date:** [August 8, 2023, 9:16am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/8 "2023-08-08T09:16:54Z")

</div>

Also, should I use this lib for react native @web3auth/solana-provider ? or I have to look for a compatible one

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [August 8, 2023, 9:22am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/9 "2023-08-08T09:22:38Z")

</div>

[Integrate Web3Auth with the Ethereum Blockchain in React Native | Documentation | Web3Auth](https://web3auth.io/docs/connect-blockchain/ethereum/react-native) This is the correct link.

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [August 8, 2023, 9:25am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/10 "2023-08-08T09:25:27Z")

</div>

Yes, you can use [@solana/web3.js](https://solana-labs.github.io/solana-web3.js/) library with Web3Auth along with `@web3auth/solana-provider` package.

---

<div class="post-metadata">

**Author:** ![yammonabd](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yammonabd](https://builder.metamask.io/u/yammonabd)\
**Post date:** [August 8, 2023, 1:05pm UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/11 "2023-08-08T13:05:33Z")

</div>

The mentioned code for init Solana requires a provider which is not returned in the react native SDK  
const solanaWallet = new SolanaWallet(web3authProvider)

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [August 8, 2023, 2:23pm UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/12 "2023-08-08T14:23:21Z")

</div>

You may refer to this [Solana Provider | Documentation | Web3Auth](https://web3auth.io/docs/sdk/helper-sdks/providers/solana)

---

<div class="post-metadata">

**Author:** ![nicomanzato](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/nicomanzato/32/315_2.png) [@nicomanzato](https://builder.metamask.io/u/nicomanzato)\
**Post date:** [August 9, 2023, 7:12pm UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/13 "2023-08-09T19:12:22Z")

</div>

I’m stuck at the same step where you are. Also opened a issue 20 days ago and still got no response : [Unable to obtain provider](https://web3auth.io/community/t/unable-to-obtain-provider/4912).

If you make it work please share how you did it!

---

<div class="post-metadata">

**Author:** ![maharshi](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/maharshi/32/1525_2.png) [@maharshi](https://builder.metamask.io/u/maharshi)\
**Post date:** [August 11, 2023, 7:14am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/14 "2023-08-11T07:14:14Z")

</div>

@yammonabd Hey, sorry for the delay. I’ll link the regular react native pnp SDK expo example [here](https://github.com/Web3Auth/web3auth-pnp-examples/blob/main/react-native/rn-expo-example/App.js). As you see, we have created a `ethersRPC.js` that allows us to perform transactions on Ethereum chain using `ethers.js`. In a similar way, you can create a `solanaRPC.js` using the `@solana/web3.js`. Sorry for the misunderstanding ,we won’t be using a `SolanaProvider` for react native PnP SDKs, you’ll find these useful when using PnP web SDKs or SFA Core-kit SDKs.  
I’ll link this as well, [How to use @solana/web3.js in a React Native app](https://solanacookbook.com/integrations/react-native.html#how-to-use-solana-web3-js-in-a-react-native-app)

---

<div class="post-metadata">

**Author:** ![yammonabd](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yammonabd](https://builder.metamask.io/u/yammonabd)\
**Post date:** [August 11, 2023, 9:17am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/15 "2023-08-11T09:17:47Z")

</div>

Hello,  
I was able to obtain the SolanaProvider.  
I will share my code for this.

```auto

import React, { useState, useEffect } from 'react';
import { TouchableOpacity, View, Text } from 'react-native';
import EncryptedStorage from 'react-native-encrypted-storage';
import * as WebBrowser from '@toruslabs/react-native-web-browser';
import Web3Auth, {
  LOGIN_PROVIDER,
  OPENLOGIN_NETWORK,
} from '@web3auth/react-native-sdk';
import {
  SolanaWallet,
  SolanaPrivateKeyProvider,
} from '@web3auth/solana-provider';
const WEB3 = {
URL: ‘test://openlogin’,
CLIENTID: ‘YOURCLIENTID’,
CHAIN: {
chainNamespace: ‘solana’,
chainId: ‘0x2’, // Please use 0x1 for Mainnet, 0x2 for Testnet, 0x3 for Devnet
rpcTarget: ‘https://api.testnet.solana.com’,
displayName: ‘Solana Test’,
blockExplorer: ‘https://explorer.solana.com’,
ticker: ‘SOL’,
tickerName: ‘Solana Token’,
},
};
const Web3 = ({}) => {
const [web3auth, setWeb3Auth] = useState(null);
const [userInfo, setUserInfo] = useState(null);
const [privKey, setPrivKey] = useState(‘’);
useEffect(() => {
const init = async () => {
try {
const auth = new Web3Auth(WebBrowser, EncryptedStorage, {
clientId: WEB3.CLIENTID,
network: OPENLOGIN_NETWORK.TESTNET,
chainConfig: WEB3.CHAIN,
});
    setWeb3Auth(auth);

    await auth.init();

    if (auth?.privKey) {
      console.log('Re logged in');

      setUserInfo(auth.userInfo());
      setPrivKey(auth.privKey);
    }
  } catch (e) {
    console.log('error', e);
  }
};
init();

}, );
const getSolanaPublicKey = async () => {
const solanaPrivateProvider =
await SolanaPrivateKeyProvider.getProviderInstance({
chainConfig: WEB3.CHAIN,
privKey: web3auth.ed25519Key,
});
const solanaWallet = new SolanaWallet(solanaPrivateProvider.provider);
const accounts = await solanaWallet.requestAccounts();
return accounts[0];

};
const login = async provider => {
try {
if (!web3auth) {
console.log(‘Web3auth not initialized’);
return;
}
console.log(‘Logging in’);
  await web3auth.login({
    loginProvider: LOGIN_PROVIDER[provider],
    redirectUrl: WEB3.URL,
  });

  if (web3auth.privKey) {
    console.log(`Logged in ${web3auth.privKey}`);

    setPrivKey(web3auth.privKey);
    setUserInfo(web3auth.userInfo());

    const publicKey = await getSolanaPublicKey();

    return {
      privateKey: web3auth.privKey,
      userInfo: web3auth.userInfo(),
      publicKey,
    };
  }
} catch (e) {
  console.log(e.message);
}

};
const logout = async () => {
if (!web3auth) {
console.log(‘Web3auth not initialized’);
return;
}
console.log(‘Logging out’);
await web3auth.logout();

if (!web3auth.privKey) {
  setUserInfo(undefined);
  setPrivKey('');

  console.log('Logged out');
}

```

Don’t forget to add extraNodeModules in your metro.config file

```auto
   //web3
      stream: require.resolve('readable-stream'),
      crypto: require.resolve('react-native-quick-crypto'),
      //solana
      https: require.resolve('https-browserify'),
      http: require.resolve('stream-http'),
      //zlib requires installing assert, util 
      zlib: require.resolve('browserify-zlib'),
      url: require.resolve('url'),

```

Tell me if you have any question

---

<div class="post-metadata">

**Author:** ![yammonabd](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yammonabd](https://builder.metamask.io/u/yammonabd)\
**Post date:** [August 11, 2023, 9:19am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/16 "2023-08-11T09:19:26Z")

</div>

Hello,  
Thank you for your response.  
Can you take a look at my shared example using SolanaProvider. Do you think it’s the wrong approach?

---

<div class="post-metadata">

**Author:** ![nicomanzato](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/nicomanzato/32/315_2.png) [@nicomanzato](https://builder.metamask.io/u/nicomanzato)\
**Post date:** [August 11, 2023, 12:30pm UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/17 "2023-08-11T12:30:52Z")

</div>

Huge thanks @yammonabd, I also share the same concern as you do. Is this the intended implementation? Is this secure considering that we are interacting with the private key directly?

---

<div class="post-metadata">

**Author:** ![maharshi](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/maharshi/32/1525_2.png) [@maharshi](https://builder.metamask.io/u/maharshi)\
**Post date:** [August 12, 2023, 9:19am UTC](https://builder.metamask.io/t/archive-i-want-to-integrate-solana-chain-with-react-native/1841/18 "2023-08-12T09:19:08Z")

</div>

Hey @yammonabd, are you able to make solana transactions? I’ll consult the team if this is a secure or the intended way.
