|
| 1 | +# Configure your agent |
| 2 | + |
| 3 | +Your agent needs to pay for the messages it sends on the XMTP network. To get started, you'll need. |
| 4 | + |
| 5 | +1. An agent built using our Node or Agent SDK |
| 6 | +2. A payer wallet that has been [funded through the XMTP Funding Portal](./fund-your-app.mdx) |
| 7 | + |
| 8 | +## Setup your Signer |
| 9 | + |
| 10 | +When you create a client, you already specify a `Signer` that is used to link your XMTP identity to a wallet. You can choose to use the same `Signer` to pay for messages, or create a new one purely for this purpose. |
| 11 | + |
| 12 | +This Signer must be of type `eoa`. The `messagePayer` may not be a smart contract wallet, since the signatures need to be able to be verified offchain. |
| 13 | + |
| 14 | +:::code-group |
| 15 | + |
| 16 | +```js [Agent] |
| 17 | +import { Agent } from '@xmtp/agent-sdk'; |
| 18 | +import { createSigner, createUser } from '@xmtp/agent-sdk/user'; |
| 19 | +import { getRandomValues } from 'node:crypto'; |
| 20 | + |
| 21 | +// Option 1: Create a local user + signer |
| 22 | +const user = createUser('0xprivateKey'); |
| 23 | +const xmtpChainRPCUrl = 'https://xmtp-testnet.my-rpc-provider.com/1234' |
| 24 | +const signer = createSigner(user); |
| 25 | + |
| 26 | +const agent = await Agent.create(signer, { |
| 27 | + env: 'testnet', // or 'production' |
| 28 | + dbEncryptionKey: getRandomValues(new Uint8Array(32)), // save it for later |
| 29 | + rpcUrls: { |
| 30 | + xmtp: xmtpChainRPCUrl, |
| 31 | + }, |
| 32 | + messagePayer: signer, // use the same signer to pay for messages or use a different wallet |
| 33 | +}); |
| 34 | +``` |
| 35 | +::: |
| 36 | + |
| 37 | +## Specify a RPC URL |
| 38 | + |
| 39 | +In order to connect to the XMTP Chain, your client needs to set a blockchain RPC URL to a provider that supports XMTP. |
| 40 | + |
| 41 | +For example, you can use [Alchemy](https://alchemy.com/) and create an app with XMTP enabled. |
| 42 | + |
| 43 | +:::code-group |
| 44 | +```js [Agent] |
| 45 | +import { Agent } from '@xmtp/agent-sdk'; |
| 46 | + |
| 47 | +const user = createUser('0xprivateKey'); |
| 48 | +const xmtpChainRPCUrl = 'https://xmtp-testnet.my-rpc-provider.com/1234' |
| 49 | +const signer = createSigner(user); |
| 50 | + |
| 51 | +const agent = await Agent.create(signer, { |
| 52 | + rpcUrls: { |
| 53 | + xmtp: xmtpChainRPCUrl |
| 54 | + } |
| 55 | +}) |
| 56 | +```` |
| 57 | + |
| 58 | +::: |
0 commit comments