https://github.com/oraichain/multicall
https://github.com/oraichain/multicall
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/oraichain/multicall
- Owner: oraichain
- License: apache-2.0
- Created: 2023-02-13T04:54:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-10T08:38:15.000Z (about 2 years ago)
- Last Synced: 2025-01-11T01:47:44.257Z (5 months ago)
- Language: Rust
- Size: 89.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Multicall
On-chain query aggregator/batcher in Oraichain.
## Build contract
```bash
cosmwasm-tools build multicontract# gen ts
cosmwasm-tools gen-ts --input multicontract --output build
```## Example Usage
### Aggregate
#### Aggregate
Init multicall
```ts
import { MulticallQueryClient } from "./build/Multicall.client";
import { CosmWasmClient, toBinary } from "@cosmjs/cosmwasm-stargate";const client = await CosmWasmClient.connect("https://testnet.rpc.orai.io");
const multicall = new MulticallQueryClient(
client,
"orai1yv8dnskhj427hd79xkk34zlvcyzkw7tve09ktp89jhr6x2r0rumsmnj07f"
);
```Example Query:
```ts
const addresses = [
'orai14n3tx8s5ftzhlxvq0w5962v60vd82h30rha573',
'orai1qdsj06kp9l92nekfxe5jmen34fz8zh86qtygca'
];
const res = await multicall.aggregate({
queries: addresses.map((address) => ({
address: 'orai1gwe4q8gme54wdk0gcrtsh4ykwvd7l9n3dxxas2',
data: toBinary({
balance: { address }
} as TokenQueryMsg)
}))
});const result = Object.fromEntries(
addresses.map((address, ind) => {
const balanceRes = fromBinary(
res.return_data[ind].data
) as BalanceResponse;
return [address, balanceRes.balance];
})
);console.log(result);
// ---
{
orai14n3tx8s5ftzhlxvq0w5962v60vd82h30rha573: '1764141066679185',
orai1qdsj06kp9l92nekfxe5jmen34fz8zh86qtygca: '0'
}
// ---
```