Skip to main content

useCreateSmartAccount

Hook for creating smart account.

import { useCreateSmartAccount } from 'moonchute';

Usage

import { useCreateSmartAccount } from 'moonchute';

function CreateSmartAccountComponent() {
const { write, data, isLoading, isError, isSuccess } = useCreateSmartAccount({
abi: contractAbi,
address: '0xContractAddress',
functionName: 'mint',
});

return (
<div>
<button 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?: CreateSmartAccountConfig) => void | undefined,
reset: () => void,
status: 'idle' | 'error' | 'loading' | 'success'
}

Parameters

The UseCreateSmartAccountConfig parameter takes an object comprised of these key attributes:

address (required)

The contract address to interact with.

abi (required)

The ABI of the contract.

functionName (required)

The function to call on the contract.

args (optional)

Arguments for the function call.

value (optional)

Value to send with the transaction (for payable functions).

Currently Supported Chains:

Chain NameChain ID
Polygon137
Arbitrum42161
Optimism10
Base8453
Mumbai80001