Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
feat: add Provider.getBytecodeByHash and `Provider.getRawBlockTrans…
Browse files Browse the repository at this point in the history
…actions`
  • Loading branch information
danijelTxFusion authored and danijelTxFusion committed Nov 27, 2023
1 parent f7d46f3 commit 021ad49
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
10 changes: 10 additions & 0 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
JsonRpcPayload,
resolveProperties,
FetchRequest,
AddressLike,
} from "ethers";
import { IERC20__factory, IEthToken__factory, IL2Bridge__factory } from "../typechain";
import {
Expand All @@ -36,6 +37,7 @@ import {
BatchDetails,
Fee,
Transaction,
RawBlockTransaction,
} from "./types";
import {
isETH,
Expand Down Expand Up @@ -264,6 +266,14 @@ export function JsonRpcApiProvider<TBase extends Constructor<ethers.JsonRpcApiPr
return await this.send("zks_getTransactionDetails", [txHash]);
}

async getBytecodeByHash(bytecodeHash: BytesLike): Promise<Uint8Array> {
return await this.send("zks_getBytecodeByHash", [bytecodeHash]);
}

async getRawBlockTransactions(number: number): Promise<RawBlockTransaction[]> {
return await this.send("zks_getRawBlockTransactions", [number]);
}

async getWithdrawTx(transaction: {
token: Address;
amount: BigNumberish;
Expand Down
34 changes: 34 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AddressLike,
assertArgument,
BigNumberish,
BytesLike,
Expand Down Expand Up @@ -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;
}
16 changes: 16 additions & 0 deletions tests/integration/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 021ad49

Please sign in to comment.