Support onchain transactions in your app built with XMTP
This content type supports sending transactions to a wallet for execution.
For Browser SDK (v6.0.0+) and Node SDK (v5.0.0+), the wallet send calls content type is built-in and does not require separate installation or codec registration.
For an example of an agent that implements the transaction content type, see xmtp-transactions.
Create a transaction request
With XMTP, a transaction request is represented using wallet_sendCalls with additional metadata for display.
Browser
const walletSendCalls = {
version: '1.0',
chainId: '1',
from: '0x1234567890',
calls: [
{
to: '0x456...def',
value: '0x5AF3107A4000',
data: '0x...',
metadata: {
description: 'Send 0.0001 ETH on base to 0x456...def',
transactionType: 'transfer',
currency: 'ETH',
amount: 100000000000000,
decimals: 18,
toAddress: '0x456...def',
},
},
{
to: '0x789...cba',
data: '0xdead...beef',
metadata: {
description: 'Lend 10 USDC on base with Morpho @ 8.5% APY',
transactionType: 'lend',
currency: 'USDC',
amount: 10000000,
decimals: 6,
platform: 'morpho',
apy: '8.5',
},
},
],
};Send a transaction request
Once you have a transaction request, you can send it as part of your conversation:
Browser
await conversation.sendWalletSendCalls(walletSendCalls);Receive a transaction request
To receive and process a transaction request:
Browser
import { contentTypesAreEqual } from '@xmtp/content-type-primitives';
import { contentTypeWalletSendCalls } from '@xmtp/browser-sdk';
const messages = await conversation.messages();
const message = messages[0];
if (contentTypesAreEqual(message.contentType, await contentTypeWalletSendCalls())) {
const walletSendCalls = message.content;
// Process the transaction request
console.log('Version:', walletSendCalls.version);
console.log('Chain ID:', walletSendCalls.chainId);
console.log('From:', walletSendCalls.from);
console.log('Calls:', walletSendCalls.calls);
}
