useSendUserOperation
Import
import { useSendUserOperation } from '@zerodev/waas'
Usage
import { useSendUserOperation, useKernelClient } from '@zerodev/waas';
import { parseAbi } from 'viem';
function App() {
const { write } = useSendUserOperation();
const { address } = useKernelClient();
const abi = parseAbi(['function mint(address _to) public']);
return (
<button
onClick={() =>
write([
{
address: '0x34bE7f35132E97915633BC1fc020364EA5134863',
abi: abi,
functionName: "mint",
args: [address],
value: 0n,
},
])
}
>
Send UserOp
</button>
)
}
Parameters
import { type UseSendUserOperationParameters } 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 UseSendUserOperationReturnType } from '@zerodev/waas'
write
(variables: SendUserOperationVariables) => void
The mutation function to send useroperation.
-
variables
-
address
Address
The contract's address. -
abi
Abi
The contract's ABI. -
functionName
string
- Function to call on the contract.
- Inferred from
abi
-
args
readonly unknown[] | undefined
- Arguments to pass when calling the contract.
- Inferred from
abi
andfunctionName
-
value
bigint | undefined
Value in wei sent with this transaction.
-
writeAsync
(variables: SendUserOperationVariables) => Promise<Hash>
Similar to write but returns a promise.
-
variables
-
address
Address
The contract's address. -
abi
Abi
The contract's ABI. -
functionName
string
- Function to call on the contract.
- Inferred from
abi
-
args
readonly unknown[] | undefined
- Arguments to pass when calling the contract.
- Inferred from
abi
andfunctionName
-
value
bigint | undefined
Value in wei 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).