Skip to content

Commit

Permalink
Merge pull request #4 from argentlabs/feat/snjs6
Browse files Browse the repository at this point in the history
feat: snjs6
  • Loading branch information
janek26 authored Mar 5, 2024
2 parents 10e2a3c + 04e2078 commit 044f04a
Show file tree
Hide file tree
Showing 17 changed files with 2,565 additions and 298 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ dist
# Stores VSCode versions used for testing VSCode extensions

.vscode-test
.vscode

# yarn v2

Expand Down
46 changes: 36 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# @argent/x-multicall

This package provides batch request functionality for Starknet RPC and Sequencer providers. It exports two classes RpcBatchProvider and SequencerBatchProvider for RPC and Sequencer providers respectively. It also exports a default function getBatchProvider which returns an instance of either RpcBatchProvider or SequencerBatchProvider based on the provider type passed to it.
This package provides batch request functionality for Starknet RPC providers.
It exports two classes: RpcBatchProvider and ContractBatchProvider.

## Installation

Expand All @@ -15,11 +16,14 @@ pnpm add @argent/x-multicall
Here is a basic usage example:

```typescript
import { getBatchProvider } from "@argent/x-multicall";
import { RpcBatchProvider } from "@argent/x-multicall";
import { RpcProvider } from "starknet";

const provider = new RpcProvider({ nodeUrl: "your_node_url" });
const batchProvider = getBatchProvider(provider);
const batchProvider = new RpcBatchProvider({
nodeUrl: rpcProvider.nodeUrl,
headers: rpcProvider.headers,
});

// Now you can use batchProvider to make batch requests
const result = batchProvider.callContract({
Expand Down Expand Up @@ -59,13 +63,13 @@ To run tests in watch mode, use:
bun run test:watch
```

## RpcBatchProvider and SequencerBatchProvider
## RpcBatchProvider

RpcBatchProvider and SequencerBatchProvider are classes that extend the RpcProvider and SequencerProvider respectively, adding batch request functionality. They can be used as follows:
RpcBatchProvider is a class that extend the RpcProvider, adding batch request functionality.

```typescript
import { RpcBatchProvider, SequencerBatchProvider } from "@argent/x-multicall";
import { RpcProvider, SequencerProvider } from "starknet";
import { RpcBatchProvider } from "@argent/x-multicall";
import { RpcProvider } from "starknet";

const rpcProvider = new RpcProvider({ nodeUrl: "your_rpc_node_url" });
const rpcBatchProvider = new RpcBatchProvider({
Expand All @@ -75,14 +79,36 @@ const rpcBatchProvider = new RpcBatchProvider({
maxBatchSize: 20,
});

const sequencerProvider = new SequencerProvider({
network: "your_network_name",
const result = rpcBatchProvider.callContract({
contractAddress: "0x0",
entrypoint: "0x0",
calldata: ["0x0"],
});
const sequencerBatchProvider = new SequencerBatchProvider(sequencerProvider);
```

In the above example, batchInterval is the time interval (in ms) at which batch requests are sent and maxBatchSize is the maximum number of requests that can be included in a batch. These options can be adjusted according to your needs.

## ContractBatchProvider

ContractBatchProvider is a class that extend MinimalProviderInterface (requires a provider with `callContract`) and allows contract batching instead of json rpc batching.

```typescript
import { ContractBatchProvider } from "@argent/x-multicall";
import { RpcProvider } from "starknet";

const rpcProvider = new RpcProvider({ nodeUrl: "your_rpc_node_url" });
const contractBatchProvider = new ContractBatchProvider(rpcProvider, {
batchInterval: 200,
maxBatchSize: 20,
});

const result = contractBatchProvider.callContract({
contractAddress: "0x0",
entrypoint: "0x0",
calldata: ["0x0"],
});
```

## License

This project is licensed under the [MIT license](LICENSE).
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@semantic-release/git": "^10.0.1",
"bun-types": "latest",
"semantic-release": "^22.0.5",
"starknet": "^5.19.5"
"starknet": "6.1.3"
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand Down
Loading

0 comments on commit 044f04a

Please sign in to comment.