'How to get all Candy Machine Ids on solana chain by web3 or json rpc
I wanna get all Candy Machine Ids on chain by web3 or json rpc call.
I have tried with getProgramAccounts json rpc but have response with Maximum response size reached.
Here is code I have tried.
curl http://api.mainnet-beta.solana.com -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getProgramAccounts",
"params": [
"cndy3Z4yapfJBmL3ShUp5exZKqR3z33thTzeNMm2gRZ",
{
"encoding": "jsonParsed",
"filters": [
]
}
]
}
How can I set filters to get Candy Machines only launched after specific date.
Or How to get only Publickey of CandyMachines in response.
Solution 1:[1]
It's easier if you use the Typescript SDK.
You can use this function https://project-serum.github.io/anchor/ts/modules/utils.rpc.html#getMultipleAccounts or https://project-serum.github.io/anchor/ts/modules/utils.rpc.html#all to get multiple accounts. It will by default collect all the accounts owned by a public key.
You can then add a filter that matches a certain number of bytes within the struct you want to address. An example would be
let ownerBytes: GetProgramAccountsFilter[] = [{
memcmp: {bytes: owner.toBase58(), offset: 8}
}];
let response = await program.account.userAccounts.all(ownerBytes);
```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DaveTheAl |