Please check my answer above. Thank you!
With .env you are âhidingâ them. Thatâs the point of creating dotenv
Getting error:
Failed to compile.
src/providers/MoralisDappProvider/MoralisDappProvider.js
Line 27:19: âReactâ is not defined no-undef
Fix?
add
import React from âreactâ;
to MoralisDappProvider.js
Getting an unexpected character error.
@jamie03also keep in mind that server url and app id are public non secret data https://docs.moralis.io/misc/faq
Have you run âyarn installâ?
aah nvm you have a typoâŚ
you forgot >
<MoralisProvider appId="APP ID" serverUrl="SERVER URL">
Fixed it. The problem was with Node.js version 17.0.1.
They changed the openssl provider. To make this work I had to change/add --open-legacy-provider to start and build in the package.json.
"scripts": {
"start": "react-scripts --openssl-legacy-provider start",
"build": "react-scripts --openssl-legacy-provider build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
Donât know yet if you have to add id to test and eject aswell.
Yes, I have. I ran that before running yarn start.
How would we go about adding more decimals to the token price display in the nav bar?
When trying to do transaction chain, this is the error
BigNumber Error: new BigNumber() number type has more than 15 significant digits: 0.9959742504000001
at ee (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-0.js:24:29614)
at new z (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-0.js:24:27841)
at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-2.js:1:656149
at Object.useMemo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:89069)
at useMemo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-3.js:1:89032)
at h (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-2.js:1:656086)
at ha (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:84902)
at Ou (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:129798)
at _s (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:115596)
at bs (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:115521)
at fs (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:112869)
at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:71307
at n.unstable_runWithPriority (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:8:32852)
at Ko (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:71016)
at Zo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:71252)
at Xo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:71187)
at ps (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:113242)
at el (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:138577)
at render (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:140494)
at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-0.js:1:5615
I was able to do this by changing the useTokenPrice.js and formatters.js.
useTokenPrice.js
import { useEffect, useState } from âreactâ;
import { useMoralis, useMoralisWeb3Api } from âreact-moralisâ;
import { c2, n4, n6, n12, tokenValueTxt } from ââŚ/helpers/formattersâ;
const useTokenPrice = (options) => {
const { token } = useMoralisWeb3Api();
const { isInitialized } = useMoralis();
const [tokenPrice, setTokenPrice] = useState();
useEffect(() => {
if (isInitialized)
fetchTokenPrice(options)
.then((price) => {
// usdPrice is a number, format() returns a string
console.log(price)
if (price.usdPrice > 0.01){
price.usdPrice = c2.format(price.usdPrice);
const { value, decimals, symbol } = price.nativePrice;
// nativePrice is an Object
// {value: string, decimals: number, name: string, symbol: string},
// tokenValueTxt returns a string
price.nativePrice = tokenValueTxt(value, decimals, symbol);
setTokenPrice(price);
}
else if (price.usdPrice > 0.0001){
price.usdPrice = n4.format(price.usdPrice);
const { value, decimals, symbol } = price.nativePrice;
price.nativePrice = tokenValueTxt(value, decimals, symbol);
setTokenPrice(price);
}
else if (price.usdPrice > 0.000001){
price.usdPrice = n6.format(price.usdPrice);
const { value, decimals, symbol } = price.nativePrice;
price.nativePrice = tokenValueTxt(value, decimals, symbol);
setTokenPrice(price);
}
else
price.usdPrice = n12.format(price.usdPrice);
const { value, decimals, symbol } = price.nativePrice;
price.nativePrice = tokenValueTxt(value, decimals, symbol);
setTokenPrice(price);
})
.catch((e) => alert(e.message));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isInitialized]);
const fetchTokenPrice = async (options) => {
const { chain, address } = options;
return await token
.getTokenPrice({ chain, address })
.then((result) => result)
.catch((e) => alert(e.message));
};
return { fetchTokenPrice, tokenPrice };
};
export default useTokenPrice;
formatters.js
export const n6 = new Intl.NumberFormat(âen-usâ, {
style: âdecimalâ,
minimumFractionDigits: 0,
maximumFractionDigits: 6,
});
export const n4 = new Intl.NumberFormat(âen-usâ, {
style: âdecimalâ,
minimumFractionDigits: 0,
maximumFractionDigits: 4,
});
export const c2 = new Intl.NumberFormat(âen-usâ, {
style: âcurrencyâ,
currency: âUSDâ,
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
export const n12 = new Intl.NumberFormat(âen-usâ, {
style: âdecimalâ,
minimumFractionDigits: 0,
maximumFractionDigits: 12,
});
/**
-
Returns a string of form âabcâŚxyzâ
-
@param {string} str string to string
-
@param {number} n number of chars to keep at front/end
-
@returns {string}
*/
export const getEllipsisTxt = (str, n = 6) => {
return ${str.substr(0, n)}...${str.substr(str.length - n, str.length)}
;
};
export const tokenValue = (value, decimals) => (decimals ? value / Math.pow(10, decimals) : value);
/**
-
Return a formatted string with the symbol at the end
-
@param {number} value integer value
-
@param {number} decimals number of decimals
-
@param {string} symbol token symbol
-
@returns {string}
*/
export const tokenValueTxt = (value, decimals, symbol) => ${n4.format(tokenValue(value, decimals))} ${symbol}
;
What is the ETA on the Solana version being released?
We donât promise any eta, we hope this year, but it will come when itâs done we need to integrate solana into Moralis first
Hi Guys, I ran both npx yarn install and npm install,
Then when running npx yarn start or npx run start I get this error.
Hey Guys,
Loving Moralis, when I try to go to localhost after npm/yarn install etc in my chrome browser Iâm getting:
from origin âhttp://localhost:3000â has been blocked by CORS policy: Response to preflight request doesnât pass access control check: No âAccess-Control-Allow-Originâ header is present on the requested resource.
How can I resolve this? The UI loads and I can connect metamask but cant pull anything in with this issue.
Thanks,
Ger