Transaction reference content type
This package provides an XMTP content type to support on-chain transaction references.
Open for feedback
You are welcome to provide feedback on this implementation by commenting on the Proposal for on-chain transaction reference content type.
What’s a transaction reference?
It is a reference to an on-chain transaction sent as a message. This content type facilitates sharing transaction hashes or IDs, thereby providing a direct link to on-chain activities.
Why transaction references?
Transaction references serve to display transaction details, facilitating the sharing of on-chain activities, such as token transfers, between users.
Install the package
npm i @xmtp/content-type-transaction-reference
yarn add @xmtp/content-type-transaction-reference
pnpm i @xmtp/content-type-transaction-reference
Create a transaction reference
With XMTP, a transaction reference is represented as an object with the following keys:
const transactionReference: TransactionReference = {
namespace: "eip155";
networkId: 1;
reference: "0x123...abc";
metadata: {
transactionType: "transfer",
currency: "USDC",
amount: 100000,
decimals: 6,
fromAddress: "0x456...def",
toAddress: "0x789...ghi"
};
};
Send a transaction reference
Once you have a transaction reference, you can send it as part of your conversation:
await conversation.messages.send(transactionReference, {
contentType: ContentTypeTransactionReference,
});
Receive a transaction reference
To receive and process a transaction reference:
const message: DecodedMessage = await loadLastMessage();
if (!message.contentType.sameAs(ContentTypeTransactionReference)) {
return;
}
const transactionRef: TransactionReference = message.content;
Display the transaction reference
Displaying a transaction reference typically involves rendering details such as the transaction hash, network ID, and any relevant metadata. The exact UI representation can vary based on your application's design, you might want to fetch on-chain data before showing them to the user.
Note on Metadata
The optional metadata within a transaction reference, such as transaction type, currency, amount, and addresses, are provided for informational purposes only. These details should not be solely relied upon for verifying transaction specifics. Developers are responsible for ensuring the accuracy of transaction data, either by directing users to the appropriate block explorer or by fetching and displaying verified transaction data from the blockchain.
Developing
Run yarn dev
to build the content type and watch for changes, which will trigger a rebuild.
Testing
Before running unit tests, start the required Docker container at the root of this repository. For more info, see Running tests.
Useful commands
yarn build
: Builds the content typeyarn clean
: Removes node_modules
, dist
, and .turbo
foldersyarn dev
: Builds the content type and watches for changes, which will trigger a rebuildyarn format
: Runs Prettier format and write changesyarn format:check
: Runs Prettier format checkyarn lint
: Runs ESLintyarn test:setup
: Starts a necessary Docker container for testingyarn test:teardown
: Stops Docker container for testingyarn test
: Runs all unit testsyarn typecheck
: Runs tsc