Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derricklee918/sol-idl-fetcher
Retrieves the IDL for a Solana program using Anchor. This includes an example with the pump.fun program's IDL.
https://github.com/derricklee918/sol-idl-fetcher
pumpfun solana solana-program spltoken
Last synced: 15 days ago
JSON representation
Retrieves the IDL for a Solana program using Anchor. This includes an example with the pump.fun program's IDL.
- Host: GitHub
- URL: https://github.com/derricklee918/sol-idl-fetcher
- Owner: derricklee918
- Created: 2024-09-16T05:33:07.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-16T05:58:10.000Z (5 months ago)
- Last Synced: 2025-01-22T02:14:06.697Z (15 days ago)
- Topics: pumpfun, solana, solana-program, spltoken
- Language: TypeScript
- Homepage:
- Size: 7.94 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Solana IDL Fetcher
This repository provides tools and scripts for fetching the Interface Definition Language (IDL) of deployed programs on the Solana blockchain using the `@project-serum/anchor` library. This project is set up using TypeScript and includes essential modules to facilitate IDL fetching and management.
Services are for hire, contact me at
https://t.me/@dwlee918## Example
In this example you can see me run the script for the pump.fun program and the marinade finance programhttps://github.com/user-attachments/assets/6eae475b-2d8f-46c2-ba7f-714a37882647
## Features
- Fetch IDL of deployed programs on the Solana blockchain.
- Saves the IDL to a json file for further usage or storage
- Easy integration into existing projects.## Prerequisites
Ensure you have the following installed:
- [Node.js](https://nodejs.org/) (version 14 or later)
- [npm](https://www.npmjs.com/)
- [TypeScript](https://www.typescriptlang.org/)## Installation
To install the package, clone the repository and install the dependencies:
```bash
git clone https://github.com/derricklee918/Sol-IDL-fetcher.git
cd Sol-IDL-fetcher
npm install
```## Usage
To compile and run the scripts:
1. Configure your environment variables as instructed.
2. Compile the TypeScript files:```bash
npx tsc
```3. Run the compiled JavaScript file:
```bash
node example.js
```## Important Note
In order to use the `fetchIdl` method, an IDL must have been previously initialized via the Anchor CLI's `anchor idl init` command. For example, the `pump.fun` program with the ID `6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P` will not work on mainnet-beta, but if you try it on devnet it will actually return the valid program IDL.
```typescript
/**
* Fetches an idl from the blockchain.
*
* In order to use this method, an IDL must have been previously initialized
* via the anchor CLI's `anchor idl init` command.
*
* @param programId The on-chain address of the program.
* @param provider The network and wallet context.
*/
public static async fetchIdl(
address: Address,
provider?: Provider
): Promise {
provider = provider ?? getProvider();
const programId = translateAddress(address);const idlAddr = await idlAddress(programId);
const accountInfo = await provider.connection.getAccountInfo(idlAddr);
if (!accountInfo) {
return null;
}
// Chop off account discriminator.
let idlAccount = decodeIdlAccount(accountInfo.data.slice(8));
const inflatedIdl = inflate(idlAccount.data);
return JSON.parse(utf8.decode(inflatedIdl));
}
```## Project Structure
- `example.ts`: Main code file
- `package.json`: Project metadata and dependencies.
- `tsconfig.json`: TypeScript configuration file.## Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your improvements.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/YourFeature`)
3. Commit your changes (`git commit -m 'Add some feature'`)
4. Push to the branch (`git push origin feature/YourFeature`)
5. Open a pull request