Hi im having a hard time invoking my setURI function from the front end. It works when I manually do it on remix. If anyone can help me figure this out much apreciated. In the console log you can see the token id and tokeURI values
Below is my hook handling the front end call and also the function from the smart contract.
import {useMoralis} from "react-moralis"
import Mint_A_Gram from ".././abi/Mint_A_Gram.json";
import { useState } from "react";
import { Uint256 } from "soltypes";
export const useSetTokenUri = (contractAddress: string, tokenId: Uint256, tokenURI: string) => {
const {Moralis} = useMoralis()
const[tokenUriState, setTokenUriState] = useState<any>({status: "waiting for tokenURI"})
const {abi} = Mint_A_Gram;
const handleSetTokenUri = async () => {
console.log(tokenId)
console.log(tokenURI)
setTokenUriState({status: "setting your token URI"})
const opts = {
chain: "rinkeby",
contractAddress: contractAddress,
functionName: "setTokenURI",
params: {tokenId,tokenURI},
abi: abi,
msgValue: "2"
}
const setTokenUri = await (Moralis as any).executeFunction(opts)
.then( (res: { data: any; }) => {
console.log(res)
}).catch((error: any) => {
console.log("error -> ", error)
});
if(setTokenUri != null || undefined)
setTokenUriState({status: tokenUriState.status.value})
}
return {handleSetTokenUri, tokenUriState}
}
function uri(uint256 tokenId) override public view returns(string memory){
return(x_uris[tokenId]);
}
function setTokenURI(uint256 tokenId, string memory uri) public {
require(bytes(x_uris[tokenId]).length == 0, "uri can only be set once.");
x_uris[tokenId] = uri;
}