For the âownerAddressHereâ, please how can I change it from a specific address to any signed in users address?
Should I replace it with the abi inputs name _owner?
You can get the loggedin user address using Moralis.User.current().get('ethAddress')
Is that what you are looking for?
You donât have to edit the ABI. Only addresses in params
need to be updated.
Yea, I was asking if I was to edit the ownerAddressHere in params with _owner?
_owner
address will be the wallet address who owns the tokens
_spender
address will be the address of the wallet or contract who can spend the tokens from _owner
address.
add the details accordingly
const options = {
chain: 'eth',
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
function_name: "allowance",
abi: [{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}],
params: {
_owner: Moralis.User.current().get('ethAddress'),
_spender: "0x016A2eaE0185af599cF770fe20a2Ad0e9Fc3BfFb"
}
};
const result = await Moralis.Web3API.native.runContractFunction(options);
console.log(result);
if(!isAuthenticated && !user) {
console.log(user);
please hereâs the edited code
sorry on my questions, iâm still a beginner.
your code look right. try running it and see what happens.
It looks like you are using react so try using the code from here with react syntax.
https://docs.moralis.io/moralis-dapp/web3-api/native#runcontractfunction
await should be inside an async function.
In react you can get user object data from useMoralis hook. Moralis.User.current()
only works when authenticated with vanilla js code
const { user } = useMoralis();
// replace Moralis.User.current() with user
_owner: user.get('ethAddress'),
i then added Moralis.start() to my .env.local file where my Moralis server and appId is, but the error kept up showing.
You donât need to add Moralis.start()
in the .env.local file. Make sure you have the appId and itâs value set in your MoralisProvider
params which is in the index.js
file. If you got it in your .env.local, makre sure itâs set properly there too having it starting with REACT_APP_...
if youâre using react and process.env.REACT_APP_...
so sorry about for my late reply. please can you show me how Iâm to add it in my index.js, please
You can check out the docs for using MoralisProvider.
If youâre using Next.js, in your _app.js:
import { MoralisProvider } from 'react-moralis';
...
<MoralisProvider serverUrl={process.env.NEXT_PUBLIC_SERVER_URL} appId={process.env.NEXT_PUBLIC_APP_ID}>
<Component {...pageProps} />
</MoralisProvider>
And in your .env.local file in your projectâs root/base directory:
NEXT_PUBLIC_SERVER_URL=urlhere
NEXT_PUBLIC_APP_ID=idhere
Thanks so much, itâs working fine now
@Blaq Iâm developing a similar Dapp to yours and I have the exact same problems ( usdt approve method integration errors and gas fee issue) you have been having and getting support about
Is it possible you share your site script or reply a few questions of mine? Can I please contact you personally for some minutes of your time? It would be a huge huge favor. Thanks in advance. Looking forward to your help!!