GhostTag

GhostTag is an npm package for tagging, streaming, and filtering Ethereum blockchain transactions that contain specific tags. It includes classes to facilitate tagging transactions and parsing tagged data.


Installation

Install the ghosttag and ethers packages using npm:

bashCopy codenpm install ghosttag ethers

Usage

Streaming Transactions

To stream transactions with a specific tag, use the GhostTagStreamer class.

Example Usage

javascriptCopy codeconst { GhostTagStreamer } = require('ghosttag');
const { ethers } = require('ethers');

const rpcUrl = 'https://1rpc.io/holesky';
const tag = 'mytag'; // can be empty for no tag filter
const dataKeys = ['tag1', 'tag2']; // can be empty for no keys and just use tag
const silent = false;

const transactions = [];
const streamer = new GhostTagStreamer(rpcUrl, tag, dataKeys, silent);

// Add filters if needed
// Example filter: only include transactions from a specific address
// streamer.addFilter((tx, data) => tx.from === '0xYourAddress');

// Add a filter for a specific tag key
// streamer.addTagKeyFilter('tag1');

// Start watching transactions and update the transactions array
streamer.start((tx) => {
    transactions.push(tx);
    console.log('Transaction:', tx);
});

Sending Tagged Transactions

To send tagged transactions, use the TaggedContract class.

Example Usage


API Reference

GhostTagStreamer

The GhostTagStreamer class is used to stream transactions with specific tags.

Constructor

  • rpcUrl: The RPC URL of the Ethereum network.

  • tag: (Optional) The tag to watch for in transactions. Defaults to an empty string.

  • dataKeys: (Optional) Keys to identify values in the transaction data. Defaults to an empty array.

  • silent: (Optional) If true, suppresses console output. Defaults to false.

Methods

toHex

Converts a string to hexadecimal.

hexToString

Converts hexadecimal to a string.

addFilter

Adds a custom filter function to filter transactions.

addTagKeyFilter

Adds a filter function for a specific tag key.

start

Starts streaming transactions and applies the filters. The callback function is called with the filtered transactions.

Callback

The callback function passed to the start method receives an object containing the following details:

  • blockNumber: The block number containing the transaction.

  • txHash: The hash of the transaction.

  • from: The sender address.

  • to: The recipient address.

  • value: The value of the transaction.

  • timestamp: The timestamp of the block containing the transaction.

  • dataHex: The hex-encoded data after the tag.

  • dataStr: The string-encoded data after the tag.

  • parsedData: The parsed key-value pairs from the data.

TaggedTransaction

The TaggedTransaction class is used to tag transactions.

Methods

tag

Tags a transaction with a custom string tag.

hextag

Tags a transaction with a custom hex tag.

TaggedContract

The TaggedContract class is a proxy for an ethers.js contract that adds tagging functionality.

Constructor

  • contract: An instance of an ethers.js contract.


License

MIT


Disclaimer

This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.

Last updated