Get from Contract
Fetch data from your deployed smart contract.
import { mega } from '@megaeth-labs/wallet-sdk';
const value = await mega.getFromContract<bigint>({
address: '0x3e942744C21Eec1D88FBD463Fd0CcE42891Aec5C',
abi: storageAbi,
functionName: 'retrieve',
args: [],
});import { useGetFromContract } from '@megaeth-labs/wallet-sdk-react';
import { useEffect } from 'react';
export default function StoredValue() {
const { mutate: getFromContract, data } = useGetFromContract();
useEffect(() => {
getFromContract({
address: '0x3e942744C21Eec1D88FBD463Fd0CcE42891Aec5C',
abi: storageAbi,
functionName: 'retrieve',
args: [],
});
}, [getFromContract]);
return <p>Stored value: {String(data ?? '…')}</p>;
}import { useReadContract } from 'wagmi';
export default function StoredValue() {
const { data } = useReadContract({
address: '0x3e942744C21Eec1D88FBD463Fd0CcE42891Aec5C',
abi: storageAbi,
functionName: 'retrieve',
});
return <p>Stored value: {String(data ?? '…')}</p>;
}Runs on testnet with your wallet
ts
interface GetFromContractRequest {
address: `0x${string}`;
abi: any;
functionName: string;
args: any[];
}
// Resolves to the function's return value