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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cartesi/viem

v2.0.0-alpha.22

Published

Cartesi viem extension

Readme

Cartesi viem extension

Viem provides an extension mechanism to clients that can provide a convenient and familiar API for application developers based on L2 solutions.

This extension provides extensions for L1 operations and L2 operations related to Cartesi.

WalletClient L1

Transactions related to Cartesi applications are sent directly to the base layer (L1). This extension provides convenient methods for sending inputs and interacting with the portals provided by Cartesi Rollups.

  • addInput
  • depositEther
  • depositERC20Tokens
  • depositERC721Token
  • depositSingleERC1155Token
  • depositBatchERC1155Token
  • executeOutput

PublicClient L1

The following methods are provided to interact with the Cartesi Rollups Smart Contracts.

  • estimateAddInputGas
  • estimateDepositEtherGas
  • estimateDepositERC20TokensGas
  • estimateDepositERC721TokenGas
  • estimateDepositSingleERC1155TokenGas
  • estimateDepositBatchERC1155TokenGas
  • estimateExecuteOutputGas
  • validateOutput

PublicClient L2

The following methods are provided to interact with the Cartesi Rollups Node.

  • listApplications
  • listEpochs
  • listInputs
  • listOutputs
  • listReports
  • getApplication
  • getEpoch
  • getInput
  • getOutput
  • getReport
  • getProcessedInputCount
  • getLastAcceptedEpoch
  • waitForInput

Utilities

  • getInputsAdded: this provides a utility method to get the input(s) added to the InputBox given a TransactionReceipt.
const receipt = await publicClient.waitForTransactionReceipt({ hash });
const [inputAdded] = getInputsAdded(receipt);

Example

Find below a complete example of depositing ERC-20 tokens and waiting for its effect on L2.

import { createPublicClient, createWalletClient, http, parseUnits } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { foundry } from "viem/chains";
import { getInputsAdded, publicActionsL2, walletActionsL1 } from "../src";

async function main() {
    const chain = foundry;
    const account = privateKeyToAccount(
        "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
    );

    // create public client to chain default url
    const publicClient = createPublicClient({ chain, transport: http() });

    // create extended public client to L2 with RPC url
    const publicClientL2 = createCartesiPublicClient({
        transport: http("http://127.0.0.1:6751/rpc"),
    });

    // create extended wallet client to chain default url
    const walletClient = createWalletClient({
        chain,
        transport: http(),
    }).extend(walletActionsL1());

    // application address
    const application = "0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e";
    const token = "0x92C6bcA388E99d6B304f1Af3c3Cd749Ff0b591e2";

    // send input transaction
    const hash = await walletClient.depositERC20Tokens({
        account,
        application,
        chain,
        token,
        amount: parseUnits("1", 18),
        execLayerData: "0x",
    });

    // wait for receipt
    const receipt = await publicClient.waitForTransactionReceipt({ hash });

    // get input index from receipt
    const [inputAdded] = getInputsAdded(receipt);
    if (inputAdded) {
        const { inputIndex } = inputAdded;

        // wait for input to be processed
        const input = await publicClientL2.waitForInput({
            inputNumber: Number(inputIndex),
        });
        console.log(input);

        // get notice 0 produced by application
        const notice = await publicClientL2.getNotice({
            inputNumber: Number(inputIndex),
            noticeNumber: 0,
        });

        console.log(notice);
    }
}

main();