Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor IDL generator #89

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ build*
.idea
cmake-build-debug
cmake-build-release

node_modules/
Empty file added lib/idl/generator/accounts.ts
Empty file.
Empty file added lib/idl/generator/errors.ts
Empty file.
Empty file.
42 changes: 42 additions & 0 deletions lib/idl/generator/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const program = require("commander");
const anchor = require('@project-serum/anchor');
const solana = require('@solana/web3.js');
const fileSystem = require("fs");


async function main() {
program
.description("generator to interact with anchor IDL")
.argument("address", "address of the deployed program")
.argument("output", " output directory")
.option("-fp, --idlFilePath [value]", "idl file path")
.parse()

const address = program.args[0]
const output = program.args[1]
const filepath = program.opts().idlFilePath || null


//Fetch IDL
const connection = new solana.Connection(solana.clusterApiUrl('mainnet-beta'))
const keypair = anchor.web3.Keypair.generate()
const wallet = new anchor.Wallet(keypair)
const provider = new anchor.AnchorProvider(connection, wallet)
const Program = new solana.PublicKey(address);
const idlFromCluster = await anchor.Program.fetchIdl(Program, provider);

//IDL From File
const idlFromFile = filepath ? JSON.parse(fileSystem.readFileSync(filepath, "utf-8")) : null


//generate classes, methods
console.log("generating programId.ts...")
console.log("generating errors.ts...")
console.log("generating instructions...")
console.log("generating types...")
console.log("generating accounts...")


}

main();
Empty file added lib/idl/generator/programId.ts
Empty file.
Empty file added lib/idl/generator/types.ts
Empty file.
Loading