Send new users an XMTP message
XMTP is a communication protocol for Web3, allowing you to build apps that communicate with every wallet in the world. In this guide you will learn to programmatically send XMTP messages to users when they sign up using a wallet.
Prerequisites
- A Dynamic account
- Completed the serverless webhooks guide
Step 1: Access the wallet address
As long as you have completed the serverless webhook guide, you’ll know how to access the email of a user within your serverless function. However in this instance, we need a wallet address.
A new user will have a wallet in two instances:
- They signup using an EOA
- They receive an embedded wallet
You can learn more about the different kinds of signup you can enable in the following section of the docs: https://docs.dynamic.xyz/sign-in-sign-up/overview. Let’s assume for now that you have both embedded wallets enabled, and EOA signups enabled so that the user object is guaranteed to have a wallet address.
When a user signs up, you can access their wallet address through the Verified Credentials array (reference here):
Step 2: Send the XMTP message
We will need to install the XMTP library for NodeJS first:
Then we can import the library and send a message:
Step 3: Call the function
Going back to our Serverless guide at Step 3, all we have to do now is add in our XMTP function call:
You can then test and redeploy your function as in Step 4 of the serverless guide, and you’re done!
Was this page helpful?