Skip to main content

useSendUserOperation

Hook for sending signed UserOp transactions to the blockchain.

import { useSendUserOperation } from 'moonchute';

Usage​

import { usePerpateUserOperation, useSendUserOperation } from 'moonchute';

function SendUserOperationComponent() {
const { config } = usePrepareUserOperation({
address: '0xContractAddress',
abi: contractAbi,
functionName: 'mint',
});
const { data, isLoading, isError, isSuccess, write } =
useSendUserOperation(config);

return (
<div>
<button disabled={!write} onClick={() => write?.()}>
Send UserOp
</button>
{isLoading && <div>Loading...</div>}
{isSuccess && <div>UserOpHash: {JSON.stringify(data?.userOpHash)}</div>}
</div>
);
}

Return Value​

{
data?: { userOpHash: Hex },
error?: Error,
isError: boolean,
isIdle: boolean,
isLoading: boolean,
isSuccess: boolean,
write: (config?: SendUserOpConfig) => void | undefined,
reset: () => void,
status: 'idle' | 'error' | 'loading' | 'success'
}

Parameters​

The SendUserOpConfig parameter is an object with the following properties:

userOp (required)​

The UserOp object containing the user operation details.

userOpHash (required)​

The hash of the UserOp object

chainId (required)​

Specifies the ID of the chain from which data needs to be fetched.

accountType​

Specifies the type of account being used.

Currently Supported Chains:​

Chain NameChain ID
Polygon137
Arbitrum42161
Optimism10
Base8453
Mumbai80001