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);


  if(!isAuthenticated && !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.

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} />

And in your .env.local file in your project’s root/base directory:


Thanks so much, it’s working fine now