In ios the button only pops the QR code. I donāt need the QR i only need the wallet connect options.
I will make those changes so i can fix the problems on some android devices where the button doesnāt do anything (neither the QR popās or the wallet connect modal).
hai @alex , i have a doubt,
the file path:ethereum-react-native-boilerplate\frontend\providers\MoralisDappProvider\MoralisDappProvider.js
How do I get ChainID dynamically?
I put a static chain id and itās fineā¦ If I put chianId: chainId it shows only for loadingā¦
(<MoralisDappContext.Provider value={{walletAddress, chianId: chainId}}>)
hereās my code:
import React, {useEffect, useMemo, useState} from āreactā;
import {useMoralis} from āreact-moralisā;
import MoralisDappContext from ā./contextā;
//import Web3 from āweb3ā; // Only when using npm/yarn
function MoralisDappProvider({children}) {
const {web3, Moralis, user} = useMoralis();
const [walletAddress, setWalletAddress] = useState();
const [chainId, setChainId] = useState();
useEffect(() => {
Moralis.onChainChanged(function (chain) {
setChainId(chain);
});
Moralis.onAccountsChanged(function (address) {
setWalletAddress(address[0]);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => setChainId(web3.givenProvider?.chainId));
useMemo(
() =>
setWalletAddress(
web3.givenProvider?.selectedAddress || user?.get(āethAddressā),
),
[web3, user],
);
return (
<MoralisDappContext.Provider value={{walletAddress, chainId:ā0x3ā}}>
{children}
</MoralisDappContext.Provider>
);
}
function useMoralisDapp() {
const context = React.useContext(MoralisDappContext);
if (context === undefined) {
throw new Error(āuseMoralisDapp must be used within a MoralisDappProviderā);
}
return context;
}
export {MoralisDappProvider, useMoralisDapp};
Hello can you read this on how to post code on this forum.
Iām not sure, maybe you canāt get the chainId with a deep link connection. If you use WalletConnect for the wallet connection, you should be able to get the chainId separately.
I get the following error when running ānpx react-native run-iosā as per the README. Can someone please help.
AppContainer@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:74305:78
[Sun Jul 17 2022 16:14:14.162] ERROR TypeError: Moralis.onAccountChanged is not a function. (In āMoralis.onAccountChanged(function (address) {
setWalletAddress(address[0]);
})ā, āMoralis.onAccountChangedā is undefined)
This error is located at:
in MoralisDappProvider (at Providers.tsx:63)
in MoralisProvider (at Providers.tsx:59)
in WalletConnectProvider (at Providers.tsx:58)
in Providers (at AppWithProviders.tsx:6)
in _default (at renderApplication.js:45)
in RCTView (at View.js:34)
in View (at AppContainer.js:106)
in RCTView (at View.js:34)
in View (at AppContainer.js:132)
in AppContainer (at renderApplication.js:39)
I used Web3 methods to get ChainID. But I donāt get ChainIDā¦
I used this code to get the chainId
āconst chainId = await web3.eth.getChainId();ā
Yeah, I customized the wallet connector myself. it is working fine.
Can you please post that code so others here can use it?
hello @alex
I used Web3 methods āconst chainId = await web3.eth.getChainId();ā for get ChainID. But I donāt get ChainIDā¦
Anyone get ChainID please let me know how to get itā¦ I used this type of method but didnāt get chainId.
const web3js = await getWeb3({connector})
const chain = Number(await web3js.eth.getChainId());
====================== getWeb3.ts =============================
import WalletConnect from "@walletconnect/client";
import Web3 from "web3";
import { AbstractProvider } from "web3-core";
import { JsonRpcPayload, JsonRpcResponse } from "web3-core-helpers";
// eslint-disable-next-line functional/prefer-readonly-type
export async function getWeb3({ connector }: { connector: WalletConnect }) {
// @ts-ignore
if (connector.connected === false){
return null;
}
const makeJsonRpcResponse = (payload: JsonRpcPayload, result: any, error?: Error): JsonRpcResponse => ({
id: +payload.id,
jsonrpc: payload.jsonrpc,
result,
error: error ? error.message : undefined,
});
const isMetamask = connector._peerMeta.name === "MetaMask" ? true : false;
const abstractProvider: AbstractProvider = {
sendAsync: (payload, callback) => {
connector
.sendCustomRequest(payload)
.then((result) => {
console.log('sendAsync result', result);
callback(null, makeJsonRpcResponse(payload, result))
})
.catch((error) => {
console.log('sendAsync error', error);
callback(error, makeJsonRpcResponse(payload, null, error))
});
},
send: (payload, callback) => {
connector
.sendCustomRequest(payload)
.then((result) => callback(null, makeJsonRpcResponse(payload, result)))
.catch((error) => callback(error, makeJsonRpcResponse(payload, null, error)));
},
connected: connector.connected,
isMetaMask: isMetamask
};
const web3 = new Web3(abstractProvider);
return web3;
}
Hi! I have a question with the expiration time of a session in the mobile app with React Native. Every time I close the app, I have to connect and sign the message again with my wallet.
Is there any chance of set a custom expiration time for each session? Where should I set this config?
I want to keep the session in each mobile phone for 24 hours.
Thank you in advance.
Since the boilerplate asks for Moralis authentication no matter what (as you have found out - you have to re-sign every time), you would have to change the start up code to detect if there is an existing WalletConnect session - see if there is some sort of local storage set which you can use.
Moralis.Plugins.rarible.lazyMint is not working in react-native. Is there any suggestion to make this function working?
Do you have the Rarible plugin installed in your server? Do you get an error?
There was an issue with the plugin where rinkeby didnāt work in the options. As plugins are now deprecated, itās recommended you use Rarible directly.
Hi everyone!
I am using the moralis react native boilerplate, and so far everything works as expected.
As my react native mobile dApp will not only store data in the blockchain but also in a custom centralized db - for which I chose a DynamoDb with AWS Lambdas on top I would need to authorize my dApp users to call my custom endpoint through the AWS API Gateway with the help of the crypto auth signatureā¦
Is there a way to do this properly because so far I havenāt found documentation about this use case? I can see that the moralis DB stores infos about the signature of the user and the session itself tooā¦ should I use webhooks to get relevant info into my custom DB and authorize with that information?
I do not own a moralis server so far just set up a Dapp quickly through the moralis website.
Please help me out with this as I only found information and docs about webapps but not with crypto authentication with react native boilerplate.
Thank you in advance,
Sandor
I would need to authorize my dApp users to call my custom endpoint through the AWS API Gateway
A way of doing this is using cloud code, or using webhooks as you have mentioned to call your API based on certain actions.
Just note that the React Native boilerplate is in alpha and is not production ready.
Suddenly I am getting this error when authenticate in react-native.
authError [Error: database or disk is full (code 13 SQLITE_FULL[13])]
Hey! Since Moralis will deprecate hosts in free tier, and they recommend to move to self hosted, is there a way to properly implement the auth?
Iāve tried to follow this: https://docs.moralis.io/docs/connect-to-your-client
but iām having a lot of issues and null pointers.
Did anyone find a way to change boilerplate to use self host moralis server?
Can you make a new topic with more info such as your project details (package.json) and exact errors youāre getting.