useTx
Basic Usage
import { useTx, useContract, shouldDisable } from 'useink'
import { pickDecoded } from 'useink/utils'
import metadata from './metadata.json'
interface Result {
color: string;
}
export const MyContractView: React.FC = () => {
const contract = useContract('..address', metadata)
const setColor = useTx<Result>(contract, 'setColor')
const args = ['blue']
return (
<>
<button onClick={() => setColor.signAndSend(args)} disable={shouldDisable(setColor)}>
{shouldDisable(setColor) ? 'Changing Color...' : 'Change Color'}
</button>
<h2>Get the result the hard way: {setColor.result.ok ? setColor.result.value.decoded.color : '--'}</h2>
<h2>Or the easy way: {pickDecoded(get.result)?.color || '--'}</h2>
</>
)
}Return Value
Transaction Statuses
Want to Learn More?
Common Patterns With useTx
Last updated