Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
zksync-ethers
Advanced tools
In order to provide easy access to all the features of zkSync Era, the zksync-ethers
JavaScript SDK was created,
which is made in a way that has an interface very similar to those of ethers. In
fact, ethers
is a peer dependency of our library and most of the objects exported by zksync-ethers
(
e.g. Wallet
, Provider
etc.) inherit from the corresponding ethers
objects and override only the fields that need
to be changed.
While most of the existing SDKs should work out of the box, deploying smart contracts or using unique zkSync features, like account abstraction, requires providing additional fields to those that Ethereum transactions have by default.
The library is made in such a way that after replacing ethers
with zksync-ethers
most client apps will work out of
box.
🔗 For a detailed walkthrough, refer to the official documentation.
To begin, it is useful to have a basic understanding of the types of objects available and what they are responsible for, at a high level:
Provider
provides connection to the zkSync Era blockchain, which allows querying the blockchain state, such as account, block or transaction details,
querying event logs or evaluating read-only code using call. Additionally, the client facilitates writing to the blockchain by sending
transactions.Wallet
wraps all operations that interact with an account. An account generally has a private key, which can be used to sign a variety of
types of payloads. It provides easy usage of the most common features.node: >= 18
(installation guide)ethers: ^5.7.0
yarn add zksync-ethers
yarn add ethers@5 # ethers is a peer dependency of zksync-ethers
The complete examples with various use cases are available here.
import { Provider, utils, types } from "zksync-ethers";
import { ethers } from "ethers";
const provider = Provider.getDefaultProvider(types.Network.Sepolia); // zkSync Era testnet (L2)
const ethProvider = ethers.getDefaultProvider("sepolia"); // sepolia testnet (L1)
const blockNumber = await provider.getBlockNumber();
const block = await provider.getBlock("latest");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
const ethBalance = await wallet.getBalance(); // balance on zkSync Era network
const ethBalanceL1 = await wallet.getBalanceL1(); // balance on Sepolia network
Transfer funds among accounts on L2 network.
const receiver = Wallet.createRandom();
const transfer = await wallet.transfer({
to: receiver,
token: utils.ETH_ADDRESS,
amount: ethers.utils.parseEther("1.0"),
});
Transfer funds from L1 to L2 network.
const deposit = await wallet.deposit({
token: utils.ETH_ADDRESS,
amount: ethers.utils.parseEther("1.0"),
});
Transfer funds from L2 to L1 network.
const withdrawal = await wallet.withdraw({
token: utils.ETH_ADDRESS,
amount: ethers.utils.parseEther("1.0"),
});
In order to run test you need to run local-setup on your machine. For running tests, use:
yarn test:wait # waits for local-setup to be ready
yarn test:prepare # prepares the environment (deploys token on both layers, etc.)
yarn test
For running test coverage, use:
yarn test:coverage
We welcome contributions from the community! If you're interested in contributing to the zksync-ethers
JavaScript SDK,
please take a look at our CONTRIBUTING.md for guidelines and details on the process.
Thank you for making zksync-ethers
JavaScript SDK better! 🙌
FAQs
A Web3 library for interacting with the ZkSync Layer 2 scaling solution.
The npm package zksync-ethers receives a total of 37,454 weekly downloads. As such, zksync-ethers popularity was classified as popular.
We found that zksync-ethers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.