@nexeth/heimdall
v0.1.3
Published
[](https://opensource.org/licenses/MIT) [](https://www.npmjs.com/package/@nexeth/heimdall) [;- Start listening to blockchain events
// Listen to new blocks
heimdall.onBlock((block) => {
console.log("New block:", block);
});
// Listen to transactions within new blocks
heimdall.onTransaction((transaction) => {
console.log("New transaction:", transaction);
});API Reference
This section details the functionalities available through @nexeth/heimdall, providing descriptions for constructors, methods, and their parameters.
Constructor
createHeimdall(config: HeimdallConfig): Heimdall
Creates a new instance of Heimdall with the specified configuration.
- Parameters:
config: HeimdallConfig- Configuration object for Heimdall.chain: Object specifying the blockchain to listen to. It should include properties likename(blockchain name) andrpcUrl(the URL to the blockchain's RPC endpoint). Chain options can be imported from viem
Example
A new instance can be instantiated using either function or class syntax
import { mainnet } from "viem/chains";
const heimdall = new Heimdall({ chain: mainnet });
// or
const heimdall = createHeimdall({ chain: mainnet });Methods
onBlock(callback: BlockActionCallback): string
Registers a callback to be executed on every new block.
- Parameters:
callback: BlockActionCallback- A function that takes aBlockobject as its parameter and returns void. This callback is called with the block information whenever a new block is mined.
- Returns: A unique identifier (
uuid) for the registered action, which can be used to remove the action later.
Example
heimdall.onBlock((block) => {
console.log("New block:", block);
});onTransaction(callback: TransactionActionCallback): string
Registers a callback to be executed for every transaction in new blocks.
- Parameters:
callback: TransactionActionCallback- A function that takes a transaction object as its parameter. This callback is called for each transaction found in a new block.
- Returns: A unique identifier (
uuid) for the registered action.
heimdall.onTransaction((transaction) => {
console.log("New transaction:", transaction);
});onTransactionHash(callback: TransactionHashActionCallback): string
Registers a callback to be executed, providing the hash for every transaction in new blocks.
- Parameters:
callback: TransactionHashActionCallback- A function that receives a transaction hash as its parameter. This callback is called with the transaction hash for each transaction in a new block.
- Returns: A unique identifier (
uuid) for the registered action.
heimdall.onTransactionHash((hash) => {
console.log("New transaction hash:", hash);
});onTransactionReceipt(callback: TransactionReceiptActionCallback): string
Registers a callback to be executed for every transaction receipt in new blocks.
- Parameters:
callback: TransactionReceiptActionCallback- A function that takes a transaction receipt object as its parameter. This callback is called for each transaction receipt found for transactions in a new block.
- Returns: A unique identifier (
uuid) for the registered action.
heimdall.onTransactionReceipt((receipt) => {
console.log("New transaction receipt:", receipt);
});removeAction(uuid: string): void
Removes a previously registered action.
- Parameters:
uuid: string- The unique identifier of the action to remove.
const heimdall = new Heimdall({ chain: mainnet });
const uuid = heimdall.onBlock(() => {});
heimdall.removeAction(uuid);Contributing
We welcome contributions from the community! If you'd like to contribute to @nexeth/heimdall, please fork the repository and submit a pull request.
- Fork the repository
- Create your feature branch: git checkout -b my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
