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

@bnb-chain/zkbnb-js-l1-sdk

v1.0.1

Published

### Install

Downloads

8

Readme

ZkBNB L1 Client

Install

Using npm:

> npm install @bnb-chain/zkbnb-js-l1-sdk

Using yarn:

> yarn add @bnb-chain/zkbnb-js-l1-sdk

Using pnpm:

> pnpm add @bnb-chain/zkbnb-js-l1-sdk

Usage

Init

import { Wallet, Provider, getZkBNBDefaultProvider } from '@bnb-chain/zkbnb-js-l1-sdk';

const rpcEndpoint = 'https://data-seed-prebsc-2-s1.binance.org:8545'; // bsc testnest rpc
const ethWallet = new ethers.Wallet(
  'your private key',
  new ethers.providers.JsonRpcProvider(rpcEndpoint)
);
const provider = getZkBNBDefaultProvider('bscTestnet'); // bsc or bscTestnet
// or by this method
// const testEndpoint = 'https://testapi.zkbnbchain.org'; // bsc testnest
// const provider = await Provider.newHttpProvider(testEndpoint);
const wallet = await Wallet.fromZkBNBSigner(ethWallet, provider);

Sign message

// this is used sign message by 
const result = await provider.ethMessageSigner().getEthMessageSignature("message");

Get Current User Address

const address = provider.address();

Get Asset Address By Asset Id

const assetAddress = await wallet.resolveTokenAddress('asset id');

Get Asset Id By Asset Address

const assetId = await wallet.resolveTokenId('asset address');

Add Asset

const tokenAddress = 'BEP20 token address';
// Before adding, it is recommended to check whether the asset exists and whether it can be added.
await wallet.addAsset({ tokenAddress });

Whether The BEP20 Token Is Approved For Deposit

const isApproved = await wallet.isBEP20DepositsApproved('BEP20 asset address');

Approve BEP20 Token For Deposit

const result = await wallet.approveBEP20TokenDeposits('BEP20 address');
// You can check if it is successful approved by the following method
const isApproved = await wallet.isBEP20DepositsApproved("BEP20 address");

Deposit BNB

const tokenAddress = await wallet.resolveTokenAddress(0);
const result = await wallet.deposit({
  to: wallet.address(),
  tokenAddress: "0x0000000000000000000000000000000000000000",
  amount: ethers.utils.parseEther('0.001'),
});

Deposit BEP20

Deposit funds from the BSC to the zkBNB.

To do the BEP20 token transfer, this token transfer should be approved. User can make BEP20 deposits approved forever using approveBEP20TokenDeposits("token address"), or the user can approve the exact amount (required for a deposit) upon each deposit using approveBEP20TokenDeposits("token address", "exact amount"), but this is not recommended.

const result = await wallet.deposit({
  to: wallet.address(),
  tokenAddress: 'BEP20 Address',
  amount: ethers.utils.parseEther('0.001'),
});

Approve NFT For Deposit

const approveTx = await this.approveForAllERC721TokenDeposits('nft address');
// You can check if it is successful approved by the following method
const isApproved = await this.isERC721DepositsApprovedForAll('nft address');

Deposit NFT

Deposit NFT from BSC to zkBNB, Only supports the nft created by zkBNB.

To do the NFT transfer, this transfer should be approved by approveForAllERC721TokenDeposits("nft address") once.

const depositResult = await wallet.depositNFT({
    to: 'wallet address', // which address to deposit to
    tokenAddress: 'nft address',
    tokenId: 'nft ID',
});

FullExit

Withdraw BNB or BEP20 from zkBNB to BSC

const result = await wallet.requestFullExit({
    tokenAddress: 'asset address',
    accountIndex: 'account index',
});

FullExit Nft

Withdraw NFT from zkBNB to BSC

const requestResult = await wallet.requestFullExitNft({
    tokenId: 'nft ID',
    accountIndex: 'account index',
});

Register A Dedicated NFT Contract For A Collection

const name = 'collection name';
const symbol = 'collection symbol';
const collectionId = 'collection Id';
await wallet.deployAndRegisterNFTFactory({
    collectionId,
    name,
    symbol,
});

Get NFT Address By Collection's Creator Address And Collection ID

const creatorAddress = 'collection creator\'s wallet address';
const collectionId = 1;
// if zero address is returned, it means a dedicated nft address can be bound
const nftAddress = await wallet.getNFTAddress(creatorAddress, collectionId);

Get NFT tokenURI

const nftContentType = 0; // 0-ipfs, 1-Greenfield
const nftContentHash = 'nft content hash';
const tokenURI = await wallet.getNftTokenURI(nftContentType, nftContentHash);

Get Pending Balance

// Please change the value of the parameter according to the actual situation
const address = 'wallet address';
const assetAddress = 'asset address';

const pendingBalance = await wallet.getPendingBalance(address, assetAddress);

Get Token Balance On BSC

const pendingBalance = await wallet.getTokenBalance('asset address');