What is the moralis version of alchemy's "createAlchemyWeb3"?

I want to mint NFT’s and for alchemy I used something like:

const web3 = createAlchemyWeb3({...});
const contract = web3.ethContract(...)
const nft = contract.methods.createToken(...)
const signedTransaction = web3.eth.accounts.signTransaction(...)
web3.eth.sendSignedTransaction(signedTransaction, private_key)

But the Moralis functions don’t give the eth object to communicate with the ethereum network

  const web3 = await Moralis.enableWeb3();
  const nativeWeb3 = Moralis.Web3API.native();

  web3.eth // undefined
  nativeWeb3.eth // undefined

Where do I get to the native web3 api?

it may depend on what version of Moralis SDK are you using: Moralis JS-SDK v1.0.0 [beta] (Ethers.js support)

I called

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

using moralis/node, but it doesn’t work, how do I enable web3 using moralis on the backend? running on node.js

you could try similar as in this post: Web3Api.initialize failed: initialize with apiKey or serverUrl error

in backend you can initialise web3 with a node RCP url directly, without the need of using Moralis

1 Like