Support onchain transaction references with your agent built with XMTP
This package provides an XMTP content type to support onchain transaction references. It is a reference to an onchain transaction sent as a message. This content type facilitates sharing transaction hashes or IDs, thereby providing a direct link to onchain activities. Transaction references serve to display transaction details, facilitating the sharing of onchain activities, such as token transfers, between users.
The transaction reference content type is built into the Agent SDK. No installation is required.
Send a transaction reference
With XMTP, a transaction reference is represented as an object with the following keys:
const transactionReference: TransactionReference = {
/**
* Optional namespace for the networkId
*/
namespace: 'eip155',
/**
* The networkId for the transaction, in decimal or hexadecimal format
*/
networkId: 1,
/**
* The transaction hash
*/
reference: '0x123...abc',
/**
* Optional metadata object
*/
metadata: {
transactionType: 'transfer',
currency: 'USDC',
amount: 100000, // In integer format, this represents 1 USDC (100000/10^6)
decimals: 6, // Specifies that the currency uses 6 decimal places
fromAddress: '0x456...def',
toAddress: '0x789...ghi',
},
};Once you have a transaction reference, you can send it as part of your conversation:
import type { TransactionReference } from '@xmtp/agent-sdk';
await ctx.conversation.sendTransactionReference(transactionReference);Receive a transaction reference
To receive and process a transaction reference, you can use the following code samples.
import type { TransactionReference } from '@xmtp/agent-sdk';
if (ctx.isTransactionReference()) {
const transactionRef: TransactionReference = ctx.message.content;
// Process the transaction reference here
}You are welcome to provide feedback on this implementation by commenting on XIP-59: Trigger on-chain calls via wallet_sendCalls.

