From 021ad49bbcf857f1564f7eaf63c457320c503ece Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Mon, 27 Nov 2023 01:10:10 +0100 Subject: [PATCH] feat: add `Provider.getBytecodeByHash` and `Provider.getRawBlockTransactions` --- package.json | 2 +- src/provider.ts | 10 +++++++++ src/types.ts | 34 ++++++++++++++++++++++++++++++ tests/integration/provider.test.ts | 16 ++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6fbbf39..1746120 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zksync2-js", - "version": "0.3.0", + "version": "0.4.0", "main": "build/src/index.js", "types": "build/src/index.d.ts", "description": "A Web3 library for interacting with the ZkSync Layer 2 scaling solution.", diff --git a/src/provider.ts b/src/provider.ts index a56485d..17e9aff 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -15,6 +15,7 @@ import { JsonRpcPayload, resolveProperties, FetchRequest, + AddressLike, } from "ethers"; import { IERC20__factory, IEthToken__factory, IL2Bridge__factory } from "../typechain"; import { @@ -36,6 +37,7 @@ import { BatchDetails, Fee, Transaction, + RawBlockTransaction, } from "./types"; import { isETH, @@ -264,6 +266,14 @@ export function JsonRpcApiProvider { + return await this.send("zks_getBytecodeByHash", [bytecodeHash]); + } + + async getRawBlockTransactions(number: number): Promise { + return await this.send("zks_getRawBlockTransactions", [number]); + } + async getWithdrawTx(transaction: { token: Address; amount: BigNumberish; diff --git a/src/types.ts b/src/types.ts index ccf88db..e9fa2cb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import { + AddressLike, assertArgument, BigNumberish, BytesLike, @@ -490,3 +491,36 @@ export interface FullDepositFee { l1GasLimit: BigInt; l2GasLimit: BigInt; } + +export interface RawBlockTransaction { + common_data: { + L2: { + nonce: number; + fee: { + gas_limit: BigInt; + max_fee_per_gas: BigInt; + max_priority_fee_per_gas: BigInt; + gas_per_pubdata_limit: BigInt; + }, + initiatorAddress: Address; + signature: Uint8Array; + transactionType: string; + input: { + hash: string; + data: Uint8Array; + }; + paymasterParams: { + paymaster: Address; + paymasterInput: Uint8Array; + }; + } + }; + execute: { + calldata: string; + contractAddress: Address; + factoryDeps: BytesLike[]; + value: BigInt; + }; + received_timestamp_ms: number; + raw_bytes: string; +} diff --git a/tests/integration/provider.test.ts b/tests/integration/provider.test.ts index c882591..1a5d14d 100644 --- a/tests/integration/provider.test.ts +++ b/tests/integration/provider.test.ts @@ -105,6 +105,22 @@ describe("Provider", () => { }); }); + describe("#getBytecodeByHash(txHash)", () => { + it("should return bytecode of a contract", async () => { + const TESTNET_PAYMASTER = "0x0f9acdb01827403765458b4685de6d9007580d15"; + const result = await provider.getBytecodeByHash(TESTNET_PAYMASTER); + expect(result).not.to.be.null; + }); + }); + + describe("#getRawBlockTransactions(number)", () => { + it("should return bytecode of a contract", async () => { + const blockNumber = await provider.getBlockNumber(); + const result = await provider.getRawBlockTransactions(blockNumber); + expect(result).not.to.be.null; + }); + }); + describe("#getTransactionStatus(txHash)", () => { it("should return transaction status", async () => { const result = await provider.getTransactionStatus(tx.hash);