npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xmtp/content-type-transaction-reference

v1.0.4

Published

An XMTP content type to support on-chain transaction references

Downloads

737

Readme

Transaction reference content type

Status Status

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
npm i @xmtp/content-type-transaction-reference

# yarn
yarn add @xmtp/content-type-transaction-reference

# pnpm
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 = {
  /**
   * Optional namespace for the networkId
   */
  namespace: "eip155";
  /**
   * The networkId for the transaction, in decimal or hexidecimal 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"
  };
};

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:

// Assume `loadLastMessage` is a thing you have
const message: DecodedMessage = await loadLastMessage();

if (!message.contentType.sameAs(ContentTypeTransactionReference)) {
  // Handle non-transaction reference message
  return;
}

const transactionRef: TransactionReference = message.content;
// Process the transaction reference here

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 type
  • yarn clean: Removes node_modules, dist, and .turbo folders
  • yarn dev: Builds the content type and watches for changes, which will trigger a rebuild
  • yarn format: Runs Prettier format and write changes
  • yarn format:check: Runs Prettier format check
  • yarn lint: Runs ESLint
  • yarn test:setup: Starts a necessary Docker container for testing
  • yarn test:teardown: Stops Docker container for testing
  • yarn test: Runs all unit tests
  • yarn typecheck: Runs tsc