useSendTransaction
Import
import { useSendTransaction } from '@zerodev/waas'
Usage
import { useSendTransaction } from '@zerodev/waas';
function App() {
const { write } = useSendTransaction();
return (
<button
onClick={() =>
write([
{
to: TO_ADDRESS,
value: VALUE,
data: DATA
},
])
}
>
Send Transactions
</button>
)
}
Parameters
import { type UseSendTransactionParameters } from '@zerodev/waas';
paymaster
{type: "SPONSOR"} | {type: "ERC20", gasToken: string} | undefined
The paymaster type and gas token address.
type
SPONSOR | ERC20
The type of paymaster.
gasToken
string | undefined
The symbol of erc20 token used for erc20 paymaster.
isParallel
boolean | undefined
- Default to
True
- The flag determine whether the user operation allows parallel execution.
nonceKey
string | undefined
The key to generate nonce for userop.
Return Types
import { type UseSendTransactionReturnType } from '@zerodev/waas'
write
(variables: SendTransactionVariables) => void
The mutation function to send transactions.
-
variables
-
to
Address
The contract's address. -
value
bigint | undefined
Value in wei sent with this transaction. -
data
Hex | undefined
Data sent with this transaction.
-
writeAsync
(variables: SendTransactionVariables) => Promise<SendTransactionData>
Similar to write but returns a promise.
-
variables
-
to
Address
The contract's address. -
value
bigint | undefined
Value in wei sent with this transaction. -
data
Hex | undefined
Data sent with this transaction.
-
data
Hash | undefined
- Defaults to
undefined
- The last successfully resolved data for the mutation.
error
Error | null
The error object for the mutation, if an error was encountered.
isError / isIdle / isPending / isSuccess
boolean
Boolean variables derived from status
.
isPaused
boolean
- will be
true
if the mutation has beenpaused
. - see Network Mode for more information.
status
'idle' | 'pending' | 'error' | 'success'
'idle'
initial status prior to the mutation function executing.'pending'
if the mutation is currently executing.'error'
if the last mutation attempt resulted in an error.'success'
if the last mutation attempt was successful.
reset
() => void
A function to clean the mutation internal state (e.g. it resets the mutation to its initial state).