Get raw TX Data in react-moralis


Currently I’m trying to migrate an application to Moralis, but on our team use case we need to modify the tx raw data after constructing it, similar to how you can do it with ethers before sending it.

I’ve tried the following methods with useWeb3Contract and useWeb3ExecutionFunction

  const contractProcessor = useWeb3ExecuteFunction();
  const options = {
    abi: contractAbi,
    contractAddress: contractAddress,
    functionName: "lend",
    params: {
      sig: "0x69a743df8888853f109620cf920686ba791585d2ae5f1464fcaa2c064b257e712c90abd375b691129a229b01fad13253d2a2cbc19cc5f65a30a26feec681b3891b",
      expiry: "1647612480",
      token: "0x25af0cca791baee922d9fa0744880ae6e0422021",
      amount: 1,

  const {
    runContractFunction: executeLendFunction,
    data: executeLendTxResponse,
  } = useWeb3Contract(options);

  async function lend() {
    // await contractProcessor.fetch({ params: options });
    contractProcessor.setData({ params: options });

I assumed that one of those console.logs was the raw tx data, but didn’t got lucky with it;

Any suggestions?

you could use ethers directly maybe if you want to modify the raw transaction

Thanks @cryptokid

I thought Moralis also had support for generating it :frowning:

Would it be possible to use Moralis together with ethers? (We currently really like the ConnectButton from moralis web3UiKit) With my previous experience using ethers we had to connect to an infuraNode and use another provider. If the answer to the previous question is positive, would you have any example code of passing the provider from ConnectButton to ethers?

We currently work in a heavily typed and strict typescript codebase, and passing window.ethereum to ethers is something that we would really like to avoid

Best Regards;

I don’t know an easy solution now

you could also try to look on GitHub on Moralis SDK code if you would know how to change it to support what you need

For anyone that could bump into the same issue:

You can get a moralis Provider and inject into ethers like so:

  const { provider } = useMoralis();
  const ethersProvider = new ethers.providers.Web3Provider(provider, "any");

Depending on your ESLint and typescript version you likely will receive an error similar to:

This is due to Moralis hook exporting the provider as an unknown (why?!):

You can then solve this error by typing the provider into an ethers external provider like so: