useCall
Usage
import { useCall } from 'useink'
import { pickDecoded } from 'useink/utils'
import metadata from 'contract/metadata.json'
const CONTRACT_ADDRESS = '...'
// We define a response type so that `get.result.value.decoded` is of type SuccessfulResponse
interface SuccessfulResponse {
foo: 'bar'
}
export const MyContractView: React.FC = () => {
const contract = useContract(CONTRACT_ADDRESS, metadata, 'astar');
const get = useCall<SuccessfulResponse>(contract, 'get');
const args = ['arg-1', 2];
return (
<>
<h1>Get the Result the hard way: {get.result?.ok ? get.result.value.decoded.foo : '--'}</h1>
<h1>Or the easy way: {pickDecoded(get.result)?.foo || '--'}</h1>
<button disabled={get.isSubmitting} onClick={() => get.send(args)}>
Get Result
</button>
</>
);
}Calling with a default caller address
Handling Result<T, E> responses from an ink! contract
Result<T, E> responses from an ink! contractReturn Value
Last updated