Hello,
I’m developing a random number dapp via React-Moralis and Chainlik.
I deployed the Chainlink smart contract and i can interact with it via React-Moralis.
I can execute the generating random number function perfectly but i don’t understand how to access the result function and to display it.
I think this is related to my missing knowledge about Javascript objects
Can you help me please?
Here is the my code:
import React from "react";
import { useWeb3ExecuteFunction } from "react-moralis";
const RandomNumber = () => {
const interactor = useWeb3ExecuteFunction();
let options = {
contractAddress: "PRIVATE",
functionName: "getRandomNumber",
abi: [
{
inputs: [],
name: "getRandomNumber",
outputs: [
{
internalType: "bytes32",
name: "requestId",
type: "bytes32",
},
],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "bytes32",
name: "requestId",
type: "bytes32",
},
{
internalType: "uint256",
name: "randomness",
type: "uint256",
},
],
name: "rawFulfillRandomness",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
stateMutability: "nonpayable",
type: "constructor",
},
{
inputs: [],
name: "randomResult",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
],
};
const interactFunction = async () => {
await interactor.fetch({
params: options,
});
};
const showNumber = async () => {
await interactor.fetch({
functionName: "randomResult",
});
};
return (
<div>
<button onClick={interactFunction}>Generate Random Number</button>
<button onClick={showNumber}>Show The Random Number</button>
</div>
);
};
export default RandomNumber;