Pregenerate User Wallets

To pregenerate an embedded wallet, you can make a POST request to the following endpoint:

https://embedded-wallet.thirdweb.com/api/v1/pregenerate

This allows you to safely create wallet addresses for your users before they login to your app.

Request Body

The request body should be a JSON object with the following parameters:

  • strategy: The strategy for wallet generation
  • email or phone or userId: The user identifier associated with the wallet to be generated

Email based wallets

{ strategy: "email", email: "[email protected]" }

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.

Phone based wallets

{ strategy: "phone", phone: "+1321123321" }

Custom user id based wallets

{ strategy: "custom_auth_endpoint", userId: "some_user_id" }

Use this when bringing your own authentication method. 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.

Headers

You need to include the following headers:

  • x-ecosystem-id: Your ecosystem ID
  • x-secret-key: Your secret key for authentication
  • Content-Type: Must be set to application/json

Example curl Command

Here's an example curl command to pregenerate an embedded wallet:

curl -X POST 'https://embedded-wallet.thirdweb.com/api/v1/pregenerate' \
-H 'x-ecosystem-id: ecosystem.example-eco-123' \
-H 'x-secret-key: 9f8e7d6c5b4a3f2e1d0c9b8a7ffge434b2a1f0e9d8c7b6a5f4e3d2c1b0a9f8e7' \
-H 'Content-Type: application/json' \
-d '{
"strategy": "email",
"email": "[email protected]"
}'

Replace the header values with your actual client ID, ecosystem ID, and secret key.

Response Format

The API returns a JSON object. The exact structure may vary based on the implementation, but it typically includes information about the pregenerated wallet. Here's a possible structure:

{
"wallet": {
"address": "string",
"createdAt": "string",
}
}

Note: The actual response may include additional fields or have a different structure. Please refer to the most up-to-date documentation for the exact response format.

Remember to handle the response appropriately in your chosen programming language, including error cases and parsing the JSON response.