From 76a770c32a814311a15fdd4efb4670b5b82932ec Mon Sep 17 00:00:00 2001 From: Adam Majmudar <64697628+adam-maj@users.noreply.github.com> Date: Thu, 28 Sep 2023 17:44:36 -0700 Subject: [PATCH] Add initial smart wallets guide (#178) --- README.md | 2 +- docs/{UserGuide.md => 1-user-guide.md} | 0 docs/2-smart-wallets.md | 53 +++++++++++++++++++++ docs/{benchmarking.md => 3-benchmarking.md} | 0 4 files changed, 54 insertions(+), 1 deletion(-) rename docs/{UserGuide.md => 1-user-guide.md} (100%) create mode 100644 docs/2-smart-wallets.md rename docs/{benchmarking.md => 3-benchmarking.md} (100%) diff --git a/README.md b/README.md index 43c5f822b..871fb01e5 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ yarn dev:infra ## User Guide -View all end-points details (Open API Specification) : [User Guide](./docs/UserGuide.md) +View all end-points details (Open API Specification) : [User Guide](./docs/1-user-guide.md) ## API Documentation diff --git a/docs/UserGuide.md b/docs/1-user-guide.md similarity index 100% rename from docs/UserGuide.md rename to docs/1-user-guide.md diff --git a/docs/2-smart-wallets.md b/docs/2-smart-wallets.md new file mode 100644 index 000000000..04362cfc3 --- /dev/null +++ b/docs/2-smart-wallets.md @@ -0,0 +1,53 @@ +## Smart Wallets + +You can use engine to deploy, manage, and transact with smart wallets on behalf of your users. + +Make sure to read the `README.md` and previous `user-guide.md` before starting this one. + +### 1. Deploy an account factory + +In order to deploy smart wallet accounts (which we'll refer to as "accounts" from here on), you'll need an `AccountFactory` contract deployed. This contract handles deploying individual `Account` contracts for your users. + +**Endpoint:** `POST - /deploy/{chain}/deployer.thirdweb.eth/AccountFactory` + +**Payload:** + +```json +{ + "constructorParams": ["0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"] +} +``` + +### 2. Deploy accounts for your users + +Once you have a factory setup, you can use it to deploy accounts for your users. + +**Endpoint:** `POST - /contract/{chain}/{account_factory_address}/account-factory/create-account` + +```json +{ + "admin_address": "0x..." // The user wallet address that you want to deploy a smart wallet for +} +``` + +This will add the `admin_address` as the primary admin that can act on behalf of the newly deployed account. + +If you want to control the account with one of your backend wallets, you can specify the backend wallet in the `admin_address` field. + +### 3. Grant permissions and sessions + +You can manage the permissions of who has control over a smart wallet. + +You can grant & revoke admins on your account with the `/contract/{chain}/{account_address}/account/admins` endpoints. + +You can grant & revoke sessions on your account which allow specific wallets to interact with specified contracts for a given period of time with the `/contract/{chain}/{account_address}/account/sessions` endpoints. + +### 4. Transact with an account + +You can make write calls with a smart account by calling any of the write endpoints and specifying both the `x-backend-wallet-address` and `x-account-address` headers. + +The `x-backend-wallet-address` should be set to the engine backend wallet that is an admin over the account. + +The `x-account-address` should be set to the deployed account address itself. + +Write calls made using these headers will initiate a `UserOperation` sent from the specified account. diff --git a/docs/benchmarking.md b/docs/3-benchmarking.md similarity index 100% rename from docs/benchmarking.md rename to docs/3-benchmarking.md