Moralis.executeFunction from

My contract function read msg.sender to return a value I pass from in Params but not working

const options = {
  contractAddress : '...',
 functionName : 'Test',
abi: [..],
params : {
 from : user.get('ethAddress')
}
}

you could try to use console.log to see if the right parameters are sent, also you may need latest or close to latest version of Moralis SDK

also you can try with a hardcoded address

I checked and options contained from : ‘0xed…’ address. I am using latest SDK

what doesn’t work? from that code I don’t know what is the problem

Solidity Code :

mapping(address => uint) UsersScore;

function Test() public view returns(uint) {
 return UsersScore[msg.sender];
}

in Web3js when i call the function I use .Call({from : '0x...'}). but in v1.0.0 sdk they remove web3js and i should use ethersJs or executeFunction.

on GitHub code of SDK i find this

if (!isReadFunction) {
      if (!params.from) {
        const currentAddress = account;
        if (!currentAddress) throw new Error('From address is required');
        contractOptions.from = currentAddress;
      }
    }

I try to pass from to Params , but it is not working!

hard code not worked too!
problem is .executeFunction not pass from for view functions.

you can use runContractFunction for view functions

that from is used when the is not a view function, in view functions you don’t need a from usually

1 Like
import Web3 from "web3";

await Moralis.start({
  serverUrl: "YOUR_SERVER_URL",
  appId: "YOUR_APP_ID",
  web3Library: Web3,
});
// Get the initialized web3 instance from Web3.js
await Moralis.enableWeb3();
const web3 = Moralis.web3;

Where should i use Moralis.start? i am using MoralisProvider

If you’re using MoralisProvider there’s already Moralis.start inside to initialize so you don’t need to run Moralis.start anymore

I want to use Web3js instance instead of etherJs

1 Like

I have the same problem. We are using MoralisProvider. So we want to enable web3.js instead of ether.js using MoralisProvider. We couldnt find a solution for that. Can anyone help please? @cryptokid @YosephKS. Thanks.

can you give more info on the context?
maybe some code example
it is react, vanilla js, nodejs, something else?

I am trying to use Web3.js instead of Ether.js by following this solution Moralis JS-SDK v1.0.0 [beta] (Ethers.js support) and
react-moralisa githhub package

But I am using MoralisProvider from react-moralis package. I am not sure what I should do after this. I tried build but I am getting build errors. @cryptokid

function MyApp({Component, pageProps, router}) {

   const { initialize, isInitialized } = useMoralis()

   const initializeMoralis = () => {
       initialize({
           appId: moralisAppID,
           serverUrl: moralisServerUrl,
           web3Library: Web3,
         })
   }

   return (
       <>
       <MoralisProvider initializeOnMount={false} >
           <LayoutWrapper {...pageProps}>
               <Component {...pageProps} />
           </LayoutWrapper>
       </MoralisProvider>

       {initializeMoralis()}

       </>
       
       
   );
}

this seems to be a question of how to use web3 instead of ethers in react with MoralisProvider

what is Web3 in this line? what happens when you run the code that you pasted?

Why do you need web3 instead of ethers in react?

you can also init Moralis SDK as in vanilla js if needed in React (separately from using MoralisProvider)

Sorry for the late reply.

  1. Web3 is an instance from Web3.js package.
  2. We are running our solution in web3 and used widely in our project. So we are planning to stick with it for now.
  3. We are using Next.js application.

Is there a way we can make the whole project to use web3.js using react-moralis SDK? @cryptokid

You will need to use web3.js directly/separately. Moralis uses ethers.js now.

But i can set web3Library in Moarlis.Start(). So can I know or is there a format i can directly use Moralis.Start() in my Next.js app?

That uses ethers in new Moralis versions.

how can i convert a token amount to usd… Using ether, while calling the transferfrom method

You can fetch the token price and use the result for 1 unit of the token to calculate the expected amount