diff --git a/docs/pages/agents/build-agents/create-a-client.mdx b/docs/pages/agents/build-agents/create-a-client.mdx index 2eb8e910..dbaf6110 100644 --- a/docs/pages/agents/build-agents/create-a-client.mdx +++ b/docs/pages/agents/build-agents/create-a-client.mdx @@ -8,14 +8,19 @@ Create an XMTP agent that can use the signing capabilities provided by a signer. import { Agent } from '@xmtp/agent-sdk'; import { createSigner, createUser } from '@xmtp/agent-sdk/user'; import { getRandomValues } from 'node:crypto'; +import { fromString } from "uint8arrays/from-string"; + +// Replace with your own wallet key and encryption key +const walletKey = "0xprivateKey"; +const encryptionKey = "encryptionKey"; // Option 1: Create a local user + signer -const user = createUser('0xprivateKey'); -const signer = createSigner(user); +const user = createUser(walletKey); +const dbEncryptionKey = fromString(encryptionKey,"hex"); const agent = await Agent.create(signer, { env: 'dev', // or 'production' - dbEncryptionKey: getRandomValues(new Uint8Array(32)), // save it for later + dbEncryptionKey: dbEncryptionKey, // save it for later }); ``` @@ -29,11 +34,11 @@ The XMTP Agent SDK allows you to use environment variables (`process.env`) for e | ------------------------ | -------------------------------------------------------------- | --------------------------------------- | | `XMTP_WALLET_KEY` | Private key for wallet | `XMTP_WALLET_KEY=0x1234...abcd` | | `XMTP_ENV` | XMTP network environment (`local`, `dev`, or `production`) | `XMTP_ENV=dev` or `XMTP_ENV=production` | -| `XMTP_DB_ENCRYPTION_KEY` | Database encryption key for the local database (32 bytes, hex) | `XMTP_DB_ENCRYPTION_KEY=0xabcd...1234` | +| `XMTP_DB_ENCRYPTION_KEY` | Database encryption key for the local database (32 bytes, hex) | `XMTP_DB_ENCRYPTION_KEY=abcd...1234` | Using the environment variables, you can setup your agent in just a few lines of code: -### Generate random keys +## Generate random keys ```tsx [Node] import { generatePrivateKey } from 'viem'; @@ -54,7 +59,7 @@ yarn gen:keys > Running the command will append keys to your existing .env file. -### Use environment variables +## Use environment variables ```tsx [Node] // Load variables from .env file @@ -66,8 +71,6 @@ const agent = await Agent.createFromEnv(); ## Configuration options -### Configure an XMTP client - You can configure an XMTP client with these options passed to `Agent.create`: ```tsx [Node]