Approve function not working

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

1 Like

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


please i got this error message.

await should be inside an async function.


please i got this error.

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 got this error message after adding the line of code.

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 :frowning:
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!!