From a9f016e8616682bf5db0b09d667d0c14f4d6ba20 Mon Sep 17 00:00:00 2001 From: Sahil Aujla Date: Tue, 26 Sep 2023 12:33:40 -0400 Subject: [PATCH] docs: add getting started page (#14) * add getting-started page * fix lint issues * ran prettier * add requested changes * Update site/getting-started.md accepted the change for "packages overview" Co-authored-by: Michael Moldoveanu --------- Co-authored-by: Michael Moldoveanu --- site/getting-started.md | 70 +++++++++++++++++++++++++++++++++- site/snippets/light-account.ts | 39 +++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 site/snippets/light-account.ts diff --git a/site/getting-started.md b/site/getting-started.md index 74cb8414c3..2c77a97a3d 100644 --- a/site/getting-started.md +++ b/site/getting-started.md @@ -1,7 +1,75 @@ --- outline: deep +head: + - - meta + - property: og:title + content: Getting Started + - - meta + - name: description + content: Getting Started with Alchemy's Account Kit + - - meta + - property: og:description + content: Getting Started with Alchemy's Account Kit --- # Getting Started -TODO +This guide will help you get started with Account Kit by setting up your environment, creating a Light Account (a type of smart account implementation), and sending a User Operation from it. By the end of this guide, you'll have a basic understanding of how to use the SDK and where to look for more advanced use cases. + +## Install the Packages + +First, create an empty directory and initialize it: +::: code-group + +```bash [npm] +mkdir account-kit +cd account-kit +npm init -y +``` + +```bash [yarn] +mkdir account-kit +cd account-kit +yarn init -y +``` + +::: + +Then you'll need to install the required packages: + +::: code-group + +```bash [npm] +npm install @alchemy/aa-alchemy @alchemy/aa-accounts @alchemy/aa-core viem +``` + +```bash [yarn] +yarn add @alchemy/aa-alchemy @alchemy/aa-accounts @alchemy/aa-core viem +``` + +::: + +## A Simple Light Account Example + +Using the SDK, we'll create a Light Account and send a User Operation from it. The Light Account will be owned by an Externally Owned Account (EOA). Here's a demonstration: + +<<< @/snippets/light-account.ts + +This initializes a `provider` for your smart account which is then used to send user operations from it. + +::: tip Note +Remember to: + +1. Replace `"0xYourEOAPrivateKey"` with your actual EOA private key. +2. Set `"ALCHEMY_API_KEY"` with your unique Alchemy API key. +3. Fund your smart account address with some SepoliaETH in order for the user operation to go through. This address is logged to the console when you run the script. +4. Adjust the `target` and `data` fields in the `sendUserOperation` function to match your requirements. + ::: + +## Dive Deeper + +In this guide we initialized `provider` with the `aa-alchemy` package however we could have done the same with the other packages of Account Kit as well. To learn more about the different packages and their use cases, check out the ["Packages Overview"](/packages/overview) page. + +## Next Steps + +To learn about the end-to-end process of integrating smart accounts in your applications check out the section on [using smart accounts](/smart-accounts/overview.html) diff --git a/site/snippets/light-account.ts b/site/snippets/light-account.ts new file mode 100644 index 0000000000..bcf2282278 --- /dev/null +++ b/site/snippets/light-account.ts @@ -0,0 +1,39 @@ +// importing required dependencies +import { AlchemyProvider } from "@alchemy/aa-alchemy"; +import { LightSmartContractAccount } from "@alchemy/aa-accounts"; +import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core"; +import { sepolia } from "viem/chains"; + +const chain = sepolia; +const PRIVATE_KEY = "0xYourEOAPrivateKey"; // Replace with the private key of your EOA that will be the owner of Light Account + +const eoaSigner: SmartAccountSigner = + LocalAccountSigner.privateKeyToAccountSigner(PRIVATE_KEY); // Create a signer for your EOA + +// Create a provider with your EOA as the smart account owner, this provider is used to send user operations from your smart account and interact with the blockchain +const provider = new AlchemyProvider({ + apiKey: "ALCHEMY_API_KEY", // Replace with your Alchemy API key, you can get one at https://dashboard.alchemy.com/ + chain, + entryPointAddress: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", // EntryPoint address for Sepolia, replace if you're using a different entry point +}).connect( + (rpcClient) => + new LightSmartContractAccount({ + entryPointAddress: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", + chain: rpcClient.chain, + owner: eoaSigner, + factoryAddress: "0xDC31c846DA74400C732edb0fE888A2e4ADfBb8b1", // Factory address for Light Account on Sepolia + rpcClient, + }) +); + +// Logging the smart account address -- please fund this address with some SepoliaETH in order for the user operations to be executed successfully +provider.getAddress().then((address: string) => console.log(address)); + +// Send a user operation from your smart contract account +const { hash } = await provider.sendUserOperation({ + target: "0xTargetAddress", // Replace with the desired target address + data: "0xCallData", // Replace with the desired call data + value: 0n, // value: bigint or undefined +}); + +console.log(hash); // Log the user operation hash