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

zkt-sdk

v1.3.9

Published

zkToken | JS SDK

Downloads

83

Readme

zkt-sdk

zkToken | JS SDK

library designed to interact with zkETH contracts on Ethereum and other supported blockchains. It provides methods to deposit native tokens and ERC-20 tokens, manage token approvals, and handle authentication.

Installation and Running

To install ZkETH, use npm or yarn:

npm install zketh

or

yarn add zketh

As a package for typescript project

Initiate zketh instance:

import { ZkEth, ethers } from "zkt-sdk";

const main = async () => {
    const provider = new ethers.JsonRpcProvider('https://ethereum-holesky.publicnode.com');
    const signer = new ethers.Wallet(privateKey, provider);

    // Define the chain ID (e.g., 17000 for holesky)
    const zkEth = new ZkEth(signer, 17000); // holesky

    try {
        const tx = await zkEth.depositNative(20n, '0x3077Bf667dBD81d3c718684Da4DE4Dc8448220E1', 0); // 20 wei

        const txReceipt = await tx.wait();

    } catch (e) {
        console.log("error:", e);
    }

    console.log('venu!');
};

main();

Example in React Project

Here's an example of how to use the zkt-lib library with ethers v5 lib:

using Ethers v6:

    import { ZkEth } from "zkt-sdk";
    import { ethers } from 'ethers';

    const provider = new ethers.BrowserProvider(window.ethereum, { name: 'polygon', chainId: 137 });

    const zkEth = new ZkEth(provider, 137);

    await zkEth.depositNative(33, '0x3077Bf667dBD81d3c718684Da4DE4Dc8448220E1', 0)

zkt-sdk also export ethers v6 instance:

import { ZkEth, SupportedChain ,ethers} from "zketh";

const provider = new ethers.JsonRpcProvider("YOUR_RPC_URL");
const signer = provider.getSigner();

// Define the chain ID (1 for Ethereum mainnet)
const chainId: SupportedChain = 1;

// Instantiate the ZkEth class
const zkEth = new ZkEth(signer, chainId);

// Use the ZkEth instance to interact with zkETH contracts
async function main() {
    const tokenContract = await zkEth.getTokenContract("usdt");
    console.log("Token contract address:", tokenContract.address);

    const depositTx = await zkEth.depositNative(BigInt("1000000000000000000"), "0xRecipientAddress");
    console.log("Deposit transaction:", depositTx);
}

main().catch(console.error);

As a package file for the nodejs

  1. Install all dependencies
yarn
  1. Generate a node js package
yarn run build

Node js version of the files will be generated to lib

Methods

  • getZkETHContract
async getZkETHContract(): Promise<ethers.Contract>

Returns an instance of the zkETH contract.

  • getTokenAddress
getTokenAddress(token: TokenName): string

Returns the address of a specified token.

token: The name of the token. Valid names are "usdt", "usdc", "link", "wsteth".

  • getTokenListsWithMetadata
getTokenListsWithMetadata(): TokenMetadataType[]

Returns a list of tokens with their metadata.

  • getTokenContract
async getTokenContract(token: TokenName): Promise<ethers.Contract>

Returns an instance of the specified token's contract.

token: The name of the token.

  • depositNative
async depositNative(
    amountInWei: bigint,
    onBehalfOf: string
): Promise<any>

Deposits native tokens (ETH/MATIC) into the zkETH contract.

amountInWei: The amount to deposit, in wei. onBehalfOf: The address on whose behalf the deposit is made.

  • approve
async approve(token: TokenName, amount: bigint): Promise<any>
Approves the zkETH contract to spend a specified amount of a token.

token: The name of the token. amount: The amount to approve.

  • revokeApprove
async revokeApprove(token: TokenName): Promise<any>
Revokes the approval for the zkETH contract to spend a specified token.

token: The name of the token.

  • allowance
async allowance(token: TokenName): Promise<any>
get the allowed amount for the zkETH contract to spend on specified token.

token: The name of the token.

  • depositTokens
async depositTokens(
    token: TokenName,
    amount: bigint,
    onBehalfOf: string
): Promise<any>

Deposits ERC-20 tokens into the zkETH contract.

token: The name of the token. amount: The amount to deposit. onBehalfOf: The address on whose behalf the deposit is made.

Development

To contribute to the development of ZkETH, clone the repository and install the dependencies:

git clone https://github.com/spaceandtimelabs/zkt-sdk-js.git
cd zketh
npm install

Contributing

We welcome contributions to zkt-sdk. Please open an issue or submit a pull request on GitHub.

License

ZkETH is released under the MIT License. See the LICENSE file for more details.