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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thyme-labs/sdk

v0.3.2

Published

SDK for authoring Web3 automation tasks

Readme

@thyme-labs/sdk

SDK for authoring Web3 automation tasks with Thyme.

Installation

npm install @thyme-labs/sdk zod viem

Usage

Create a task with embedded schema:

import { defineTask, z } from '@thyme-labs/sdk'
import { encodeFunctionData } from 'viem'

const abi = [
  {
    name: 'updatePrice',
    type: 'function',
    stateMutability: 'nonpayable',
    inputs: [{ name: 'price', type: 'uint256' }],
    outputs: [],
  },
  {
    name: 'getPrice',
    type: 'function',
    stateMutability: 'view',
    inputs: [],
    outputs: [{ type: 'uint256' }],
  },
] as const

export default defineTask({
  // Define your arguments schema with type-safe Ethereum addresses
  schema: z.object({
    oracleAddress: z.address(), // Validates and returns viem's Address type
    threshold: z.number().min(0),
  }),

  // Main execution logic
  async run(ctx) {
    const { oracleAddress, threshold } = ctx.args
    
    // Read from blockchain using the public client
    const lastPrice = await ctx.client.readContract({
      address: oracleAddress,
      abi,
      functionName: 'getPrice',
    })
    
    // Your logic here
    const price = await fetchPrice()
    
    if (price > threshold && price !== lastPrice) {
      return {
        canExec: true,
        calls: [{
          to: oracleAddress,
          data: encodeFunctionData({
            abi,
            functionName: 'updatePrice',
            args: [price],
          }),
        }]
      }
    }
    
    return {
      canExec: false,
      message: 'Price below threshold or unchanged'
    }
  },

  // Optional: Handle successful execution
  async onSuccess(ctx, txHashes) {
    console.log('Executed:', txHashes)
  },

  // Optional: Handle failed execution
  async onFail(ctx, error) {
    console.error('Failed:', error.message)
  },
})

Schema Validation

The SDK provides an extended Zod instance with Ethereum-specific validators:

z.address()

Validates an Ethereum address and returns viem's Address type:

import { defineTask, z } from '@thyme-labs/sdk'

export default defineTask({
  schema: z.object({
    targetAddress: z.address(), // Validates checksum and format
  }),
  async run(ctx) {
    // ctx.args.targetAddress is typed as Address from viem
    return {
      canExec: true,
      calls: [{
        to: ctx.args.targetAddress,
        data: '0x',
      }]
    }
  }
})

You can also use standard Zod validators:

schema: z.object({
  address: z.address(),
  amount: z.bigint().positive(),
  enabled: z.boolean(),
  metadata: z.string().optional(),
})

Public Client

The context includes a viem PublicClient for reading blockchain data:

import { defineTask, z } from '@thyme-labs/sdk'

export default defineTask({
  schema: z.object({
    tokenAddress: z.address(),
    threshold: z.bigint(),
  }),
  
  async run(ctx) {
    // Read contract state
    const totalSupply = await ctx.client.readContract({
      address: ctx.args.tokenAddress,
      abi: [{
        name: 'totalSupply',
        type: 'function',
        stateMutability: 'view',
        inputs: [],
        outputs: [{ type: 'uint256' }],
      }],
      functionName: 'totalSupply',
    })
    
    // Get block data
    const blockNumber = await ctx.client.getBlockNumber()
    const block = await ctx.client.getBlock({ blockNumber })
    
    // Get balance
    const balance = await ctx.client.getBalance({
      address: ctx.args.tokenAddress,
    })
    
    if (totalSupply > ctx.args.threshold) {
      return {
        canExec: true,
        calls: [...]
      }
    }
    
    return {
      canExec: false,
      message: 'Threshold not met'
    }
  }
})

The client is configured using the RPC_URL environment variable in your .env file.

Encoding Function Calls

Use viem's encodeFunctionData to encode function calls:

import { defineTask, z } from '@thyme-labs/sdk'
import { encodeFunctionData } from 'viem'

const abi = [
  'function transfer(address to, uint256 amount) returns (bool)',
] as const

export default defineTask({
  schema: z.object({
    token: z.address(),
    recipient: z.address(),
  }),
  
  async run(ctx) {
    return {
      canExec: true,
      calls: [{
        to: ctx.args.token,
        data: encodeFunctionData({
          abi,
          functionName: 'transfer',
          args: [ctx.args.recipient, 1000n],
        }),
      }]
    }
  }
})

Viem's encodeFunctionData provides full type safety and validation.

API

defineTask(definition)

Define a Web3 automation task.

Parameters

  • definition.schema - Zod schema for validating task arguments
  • definition.run - Main execution function that returns whether to execute and what calls to make
  • definition.onSuccess - Optional callback on successful execution
  • definition.onFail - Optional callback on failed execution

Returns

The task definition (for type inference).

Types

ThymeContext<TArgs>

Context provided to task execution:

  • args - User-provided arguments validated against schema
  • client - Viem public client for reading blockchain data

TaskResult

Result from task execution:

  • { canExec: true, calls: Call[] } - Execute these calls
  • { canExec: false, message: string } - Don't execute, with reason

Call

A call to execute on-chain:

  • to - Target contract address
  • data - Encoded function call data

License

MIT