|
| 1 | +import { Callout} from "@doc"; |
| 2 | + |
| 3 | +# Pregenerate User Wallets |
| 4 | + |
| 5 | +To pregenerate an in-app or ecosystem wallet wallet, you can make a `POST` request to the following endpoint: |
| 6 | + |
| 7 | +``` |
| 8 | +https://in-app-wallet.thirdweb.com/api/v1/pregenerate |
| 9 | +``` |
| 10 | + |
| 11 | +This allows you to safely create wallet addresses for your users before they login to your app. |
| 12 | + |
| 13 | +## Request Body |
| 14 | + |
| 15 | +The request body should be a JSON object with the following parameters: |
| 16 | + |
| 17 | +- `strategy`: The strategy for wallet generation |
| 18 | +- `email` or `phone` or `userId`: The user identifier associated with the wallet to be generated |
| 19 | + |
| 20 | +### Email based wallets |
| 21 | + |
| 22 | +``` |
| 23 | +{ strategy: "email", email: "[email protected]" } |
| 24 | +``` |
| 25 | + |
| 26 | +When the user logs in with any method associated with that email (including google, facebook, discord auth), they will get access to the same pregenerated wallet. |
| 27 | + |
| 28 | +### Phone based wallets |
| 29 | + |
| 30 | +``` |
| 31 | +{ strategy: "phone", phone: "+1321123321" } |
| 32 | +``` |
| 33 | + |
| 34 | +### Custom user id based wallets |
| 35 | + |
| 36 | +``` |
| 37 | +{ strategy: "custom_auth_endpoint", userId: "some_user_id" } |
| 38 | +``` |
| 39 | + |
| 40 | +{/* TODO: update link when custom auth documentation has been updated */} |
| 41 | +Use this when [bringing your own authentication method](/connect/in-app-wallet/custom-auth/configuration). When the user logs in, if the user ids you provide from the auth endpoint match, they will get access to the same pregenerated wallet. |
| 42 | + |
| 43 | +## Headers |
| 44 | + |
| 45 | +You need to include the following headers: |
| 46 | + |
| 47 | +- `Content-Type`: Must be set to `application/json` |
| 48 | +- `x-secret-key`: Your secret key for authentication |
| 49 | +- `x-ecosystem-id` (optional): Your ecosystem ID |
| 50 | +- `x-ecosystem-partner-id` (optional): Your ecosystem partner ID |
| 51 | + |
| 52 | +## Example curl Command |
| 53 | + |
| 54 | +Here's an example curl command to pregenerate a thirdweb wallet for the user `[email protected]`: |
| 55 | + |
| 56 | +```bash |
| 57 | +curl -X POST 'https://embedded-wallet.thirdweb.com/api/v1/pregenerate' \ |
| 58 | + -H 'x-ecosystem-id: ecosystem.example-eco-123' \ |
| 59 | + -H 'x-ecosystem-partner-id: 1415d24e-c7b0-4fce-846e-740841ef2c32' \ |
| 60 | + -H 'x-secret-key: 9f8e7d6c5b4a3f2e1d0c9b8a7ffge434b2a1f0e9d8c7b6a5f4e3d2c1b0a9f8e7' \ |
| 61 | + -H 'Content-Type: application/json' \ |
| 62 | + -d '{ |
| 63 | + "strategy": "email", |
| 64 | + |
| 65 | + }' |
| 66 | +``` |
| 67 | + |
| 68 | +Replace the header values with your actual client ID, ecosystem ID, and secret key. |
| 69 | + |
| 70 | +<Callout variant='info' title='Pregeneration for ecosystems'> |
| 71 | +For ecosystem wallets, the secret key have to be from the same account as the ecosystem owner. If this is an issue, please reach out to us. |
| 72 | +</Callout> |
| 73 | + |
| 74 | + |
| 75 | +## Response Format |
| 76 | + |
| 77 | +A successful API call returns a JSON object in the following format: |
| 78 | + |
| 79 | +```json |
| 80 | +{ |
| 81 | + "wallet": { |
| 82 | + "address": "string", |
| 83 | + "createdAt": "string", |
| 84 | + } |
| 85 | +} |
| 86 | +``` |
0 commit comments