-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> --------- Co-authored-by: Michael Moldoveanu <[email protected]>
- Loading branch information
1 parent
239b653
commit a9f016e
Showing
2 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |