Iām fairly new to interacting with blockchains so this could be something simple Iāve misunderstood, but I am getting 400 errors and āInvalid function: āgetNFTsāā errors. Iāve tried using some of the troubleshooting code samples posted on this forum to attempt to rule out an issue with my code but everything Iāve tried gives me the same errors. MetaMask connects and signs as I think it should.
Hereās the current code:
<html>
<head>
<!-- Moralis SDK code -->
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
</head>
<body>
<h1>Moralis Test</h1>
<button id="btn-login">Moralis Login</button>
<button id="btn-getnftbalances">Get NFT Balances</button>
<button id="btn-logout">Logout</button>
<script>
// connect to Moralis server
Moralis.initialize("OkTXIluu6w2ftgLQ2YeD5LIYHUbcBKWhc6Z9KHgz");
Moralis.serverURL = "https://jok6y0o5mjko.usemoralis.com:2053/server";
async function login() {
let user = Moralis.User.current();
if (!user) {
user = await Moralis.Web3.authenticate();
}
console.log("logged in user:", user);
}
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
}
async function getNFTBalances() {
const options = {chain: 'binance smart chain', address: '0x90099da42806b21128a094c713347c7885af79e2'};
const nfts = await Moralis.Web3.getNFTs(options);
console.log(nfts);
}
// bind button click handlers
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
document.getElementById("btn-getnftbalances").onclick = getNFTBalances;
</script>
</body>
</html>
And here is the console output:
moralis.js:21917 POST https://jok6y0o5mjko.usemoralis.com:2053/server/functions/getNFTs 400
dispatch @ moralis.js:21917
ajax @ moralis.js:21924
(anonymous) @ moralis.js:22028
Promise.then (async)
request @ moralis.js:22022
run @ moralis.js:427
run @ moralis.js:353
value @ moralis.js:5278
getNFTBalances @ test2.html:38
moralis.js:24018 Uncaught (in promise) Error: Invalid function: "getNFTs"
at handleError (moralis.js:22050)
at async HTMLButtonElement.getNFTBalances (test2.html:38)
_construct @ moralis.js:24018
Wrapper @ moralis.js:24422
(anonymous) @ moralis.js:8462
ParseError @ moralis.js:8513
handleError @ moralis.js:22050
async function (async)
getNFTBalances @ test2.html:38
The server is on 0.0.244 and Iāve tried redeploying it a few times (and each time Iāve been changing my Server URL and Application ID in the code) but that doesnāt seem to help.
Thanks