useTx
Creates and manages general Substrate transactions with improved type safety. Provides functions to sign and send transactions, estimate fees, and track transaction progress.
Props
txBuilder
(tx) => TxFunction
Callback function that receives the tx object and returns a transaction method (e.g., (tx) => tx.system.remark).
options
NetworkOptions?
Optional network selection options (e.g., { networkId: 'polkadot' }).
Return Type
signAndSend
(params?) => Promise<void>
Function to sign and send the transaction. Accepts { args?, txOptions?, callback? }.
getEstimatedFee
(params?) => Promise<bigint>
Function to estimate the transaction fee. Accepts { args?, txOptions? }.
inProgress
boolean
Whether a transaction is currently in progress (from signing to finalization).
inBestBlockProgress
boolean
Whether the transaction has been included in the best block.
Basic Usage
System remark transaction:
import { useTx } from 'typink';
function RemarkExample() {
const remarkTx = useTx((tx) => tx.system.remark);
const handleSend = async () => {
await remarkTx.signAndSend({
args: ['Hello from Typink!'],
callback: (result) => {
console.log('Transaction status:', result.status.type);
},
});
};
return (
<button
onClick={handleSend}
disabled={remarkTx.inBestBlockProgress}>
{remarkTx.inBestBlockProgress ? 'Sending...' : 'Send Remark'}
</button>
);
}Balance transfer transaction:
Last updated
Was this helpful?