Skip to content

Instantly share code, notes, and snippets.

@TABASCOatw
Created October 13, 2023 05:25
Show Gist options
  • Save TABASCOatw/56fb521ba4d42d6b4d075108af3fc5ed to your computer and use it in GitHub Desktop.
Save TABASCOatw/56fb521ba4d42d6b4d075108af3fc5ed to your computer and use it in GitHub Desktop.
Leveraging Particle WaaS as a signer within Alchemy's Account Kit
import { ParticleNetwork } from '@particle-network/auth';
import { ParticleProvider } from '@particle-network/provider';
import { AlchemyProvider } from "@alchemy/aa-alchemy";
import { LightSmartContractAccount } from "@alchemy/aa-accounts";
import { polygonMumbai } from "viem/chains";
import { createWalletClient, custom } from "viem";
import { WalletClientSigner, SmartAccountSigner } from "@alchemy/aa-core";
const particle = new ParticleNetwork({
projectId: process.env.REACT_APP_PROJECT_ID as string,
clientKey: process.env.REACT_APP_CLIENT_KEY as string,
appId: process.env.REACT_APP_APP_ID as string,
chainName: 'polygon',
chainId: 80001,
});
const particleProvider = new ParticleProvider(particle.auth);
// Assumes user has logged in with something like particle.auth.login(), Particle Connect, or through other misc. connection
const particleWalletClient = createWalletClient({
transport: custom(particleProvider),
});
export const particleSigner: SmartAccountSigner = new WalletClientSigner(
particleWalletClient,
"particle"
);
const chain = polygonMumbai;
const ENTRY_POINT_CONTRACT_ADDRESS = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
const FACTORY_CONTRACT_ADDRESS = "0x000000893A26168158fbeaDD9335Be5bC96592E2";
const provider = new AlchemyProvider({
apiKey: process.env.ALCHEMY_API_KEY as string,
chain,
entryPointAddress: ENTRY_POINT_CONTRACT_ADDRESS,
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
entryPointAddress: ENTRY_POINT_CONTRACT_ADDRESS,
chain: rpcClient.chain,
owner: particleSigner,
factoryAddress: FACTORY_CONTRACT_ADDRESS,
rpcClient,
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment