It is strongly discouraged to use private key or mnemonic import/generate function, if you use it, you need to secure the data yourself, Particle's SDK has no relationship with the imported/generated mnemonic or private key.
1.Add the Connect Service SDK to Your React Native App
3.7. Configure your app scheme URL, select your app from TARGETS, under Info section, click + to add the URL types, and paste your scheme in URL Schemes
Your scheme URL should be "pn" + your project app uuid.
For example, if your project app id is "63bfa427-cf5f-4742-9ff1-e8f5a1b9828f", your scheme URL is "pn63bfa427-cf5f-4742-9ff1-e8f5a1b9828f".
3.8 In Xcode right-click your Info.plist file and choose "Open As Source Code".
Copy & Paste the XML snippet into the body of your file (<dict>...</dict>).
Before using the sdk you have to call init(Required)
// Get your project id and client key from dashboard, // https://dashboard.particle.network/ParticleInfo.projectId =''; // your project idParticleInfo.clientKey =''; // your client key
Migrating to WalletConnect v2
Starting from version 0.14.0, WalletConnectV2 is supported.
// Init particle connect SDK,// metadata is your app info, will pass to wallet when wallet connect.// you can use the values that we provided in example.const chainInfo =ChainInfo.EthereumGoerli;const env =Env.Dev;const metadata =newDappMetaData('75ac08814504606fc06126541ace9df6','Particle Connect','https://connect.particle.network/icons/512.png','https://connect.particle.network','Particle Wallet', "", "");particleConnect.init(chainInfo, env, metadata);// set wallet connect support chaininfos, if you dont call this method// default value is current chaininfo.const chainInfos = [Ethereum, Polygon, EthereumGoerli, EthereumSepolia];particleConnect.setWalletConnectV2SupportChainInfos(chainInfos);
Connect
Web3 provider
you can use our SDK as a web3 provider
import Web3 from'web3';// Start with new web3, at this time, you don't connect with this walletType, and dont know any publicAddressvar newWeb3:Web3;// After connected a wallet, restoreWeb3 when getAccounts.// We need to check if the walletType and publicAddress is connected. var web3:Web3;newWeb3_getAccounts=async () => {try {constaccounts=awaitnewWeb3.eth.getAccounts(); pnaccount =newPNAccount("","",accounts[0] asstring,"");console.log('web3.eth.getAccounts', accounts); } catch (error) {console.log('web3.eth.getAccounts', error); }}restoreWeb3_getAccounts=async () => {try {console.log('pnaccount.publicAddress ',pnaccount.publicAddress); web3 =restoreWeb3('your project id','your client key',PNAccount.walletType,pnaccount.publicAddress);constaccounts=awaitweb3.eth.getAccounts();console.log('web3.eth.getAccounts', accounts); } catch (error) {console.log('web3.eth.getAccounts', error); }}web3_getBalance=async () => {try {constaccounts=awaitweb3.eth.getAccounts();constbalance=awaitweb3.eth.getBalance(accounts[0]);console.log('web3.eth.getBalance', balance); } catch (error) {console.log('web3.eth.getBalance', error); }}web3_getChainId=async () => {try {constchainId=awaitweb3.eth.getChainId();console.log('web3.eth.getChainId', chainId); } catch (error) {console.log('web3.eth.getChainId', error); }}web3_personalSign=async () => {// for persion_sign// don't use web3.eth.personal.signtry {constaccounts=awaitweb3.eth.getAccounts();constresult=awaitweb3.currentProvider.request({ method:'personal_sign', params: ['hello world', accounts[0]] });console.log('web3.eth.personal.sign', result); } catch (error) {console.log('web3.eth.personal.sign', error); }}web3_signTypedData_v4=async () => {try {constaccounts=awaitweb3.eth.getAccounts();constresult=awaitweb3.currentProvider.request({ method:'eth_signTypedData_v4', params: [accounts[0], { 'your typed data v4' }] });console.log('web3 eth_signTypedData_v4', result); } catch (error) {console.log('web3 eth_signTypedData_v4', error); }}web3_sendTransaction=async () => {try {constaccounts=awaitweb3.eth.getAccounts();constresult=awaitweb3.eth.sendTransaction( { from: accounts[0], to:'a receiver address or contract address', value:'1000000', data:'0x' } )console.log('web3.eth.sendTransaction', result); } catch (error) {console.log('web3.eth.sendTransaction', error); }}web3_wallet_switchEthereumChain=async () => {try {constchainId="0x"+EvmService.currentChainInfo.chain_id.toString(16);constresult=awaitweb3.currentProvider.request({ method:'wallet_switchEthereumChain', params: [{ chainId }] })console.log('web3 wallet_switchEthereumChain', result); } catch (error) {console.log('web3 wallet_switchEthereumChain', error); }}web3_wallet_addEthereumChain=async () => {try {constchainId="0x"+EvmService.currentChainInfo.chain_id.toString(16);constresult=awaitweb3.currentProvider.request({ method:'wallet_addEthereumChain', params: [{ chainId }] })console.log('web3 wallet_addEthereumChain', result); } catch (error) {console.log('web3 wallet_addEthereumChain', error); }}
Connect
// connect exampleconstresult=awaitparticleConnect.connect(PNAccount.walletType);if (result.status) {console.log('connect success');constaccount=result.data;this.pnaccount =newPNAccount(account.icons,account.name,account.publicAddress,account.url );console.log('pnaccount = ',this.pnaccount); } else {console.log('connect failure');consterror=result.data;console.log(error); }};// connect with particle, support pass more parameters// set login type, account, support types and login form modeconstconnectConfig=newParticleConnectConfig(LoginType.Phone,'', [SupportAuthType.Email,SupportAuthType.Google,SupportAuthType.Apple, ]);constresult=awaitparticleConnect.connect(WalletType.Particle, connectConfig );if (result.status) {console.log('connect success');constaccount=result.data;this.pnaccount =newPNAccount(account.icons,account.name,account.publicAddress,account.url );console.log('pnaccount = ',this.pnaccount); } else {console.log('connect failure');consterror=result.data;console.log(error); }};
only support iOS, usually use when open app, if current wallet is from wallet connect, call this method to reconnect, you can call this method anywhere anytime.