Viem
Install
npm i @cometh/connect-sdk-4337 @viem
yarn @cometh/connect-sdk-4337 @viem
Create a smart account
import { ENTRYPOINT_ADDRESS_V07, createSafeSmartAccount,
createSmartAccountClient } from "@cometh/connect-sdk-4337";
const apiKey = process.env.COMETH_API_KEY;
const rpcUrl = process.env.RPC_URL;
const smartAccount = await createSafeSmartAccount({
apiKey,
rpcUrl,
entryPoint: ENTRYPOINT_ADDRESS_V07,
});
Get smart account address
const address = smartAccount.address
Create a smart account client
import { ENTRYPOINT_ADDRESS_V07, createSafeSmartAccount,
createSmartAccountClient } from "@cometh/connect-sdk-4337";
import { http } from "viem"
const apiKey = process.env.COMETH_API_KEY;
const bundlerUrl = process.env.4337_BUNDLER_URL;
const rpcUrl = process.env.RPC_URL;
const smartAccount = await createSafeSmartAccount({
apiKey,
rpcUrl,
entryPoint: ENTRYPOINT_ADDRESS_V07,
});
const smartAccountClient = createSmartAccountClient({
account: smartAccount,
entryPoint: ENTRYPOINT_ADDRESS_V07,
chain: arbitrumSepolia,
bundlerTransport: http(bundlerUrl)
})
Send a transaction
import { encodeFunctionData } from "viem"
import countContractAbi from "@/contract/counterABI.json";
const calldata = encodeFunctionData({
abi: countContractAbi,
functionName: "count",
});
const txHash = await smartAccountClient.sendTransaction(
{
to: COUNTER_CONTRACT_ADDRESS,
data: calldata,
}
);
Batch transactions
import { encodeFunctionData } from "viem"
import countContractAbi from "@/contract/counterABI.json";
const calldata = encodeFunctionData({
abi: countContractAbi,
functionName: "count",
});
const txHash = await smartAccountClient.sendTransactions(
{
transactions: [
{
to: COUNTER_CONTRACT_ADDRESS,
data: calldata,
},
{
to: COUNTER_CONTRACT_ADDRESS,
data: calldata,
},
],
}
);
Retrieve smart account address from passkey
import { retrieveAccountAddressFromPasskey } from "@cometh/connect-sdk-4337";
const apiKey = process.env.COMETH_API_KEY;
const walletAddress = await retrieveAccountAddressFromPasskey(apiKey);
Last updated