Skip to main content
deleted 144 characters in body
Source Link
McBain
  • 5.4k
  • 9
  • 33

Your idl inside the generated typescript file should have the following format:

export type SomeProgram = {
  "version": "0.1.0",
  "name": "some_program",
  "instructions": [// Instructions here],
  "accounts:":[// Accounts defs here, what we'll be accessing below],
  "types":[// Custom types here],
  "errors":[//Errors here],
};

export const IDL: SomeProgram = {
  "version": "0.1.0",
  "name": "some_program",
  "instructions": [// Instructions here],
  "accounts:":[// Accounts here],
  "types":[// Custom types here],
  "errors":[//Errors here],
};

After you've validated this is the format, you should just be able to import it in your tests like below and get the type of some account, like this (assuming you want the account type at index 1 inside your idl definitioncalled myAccountType):

import * as anchor from "@coral-xyz/anchor";
import { SomeProgram } from '../target/types/some_program'
let myAccount : SomeProgram['accounts'][1]anchor.IdlAccounts<SomeProgram>['myAccountType'] 

This is called lookup types by the way.

Your idl inside the generated typescript file should have the following format:

export type SomeProgram = {
  "version": "0.1.0",
  "name": "some_program",
  "instructions": [// Instructions here],
  "accounts:":[// Accounts defs here, what we'll be accessing below],
  "types":[// Custom types here],
  "errors":[//Errors here],
};

export const IDL: SomeProgram = {
  "version": "0.1.0",
  "name": "some_program",
  "instructions": [// Instructions here],
  "accounts:":[// Accounts here],
  "types":[// Custom types here],
  "errors":[//Errors here],
};

After you've validated this is the format, you should just be able to import it in your tests like below and get the type of some account, like this (assuming you want the account type at index 1 inside your idl definition):

import { SomeProgram } from '../target/types/some_program'
let myAccount : SomeProgram['accounts'][1] 

This is called lookup types by the way.

Your idl inside the generated typescript file should have the following format:

export type SomeProgram = {
  "version": "0.1.0",
  "name": "some_program",
  "instructions": [// Instructions here],
  "accounts:":[// Accounts defs here, what we'll be accessing below],
  "types":[// Custom types here],
  "errors":[//Errors here],
};

export const IDL: SomeProgram = {
  "version": "0.1.0",
  "name": "some_program",
  "instructions": [// Instructions here],
  "accounts:":[// Accounts here],
  "types":[// Custom types here],
  "errors":[//Errors here],
};

After you've validated this is the format, you should just be able to import it in your tests like below and get the type of some account, like this (assuming you want the account type called myAccountType):

import * as anchor from "@coral-xyz/anchor";
import { SomeProgram } from '../target/types/some_program'
let myAccount : anchor.IdlAccounts<SomeProgram>['myAccountType'] 
Source Link
McBain
  • 5.4k
  • 9
  • 33

Your idl inside the generated typescript file should have the following format:

export type SomeProgram = {
  "version": "0.1.0",
  "name": "some_program",
  "instructions": [// Instructions here],
  "accounts:":[// Accounts defs here, what we'll be accessing below],
  "types":[// Custom types here],
  "errors":[//Errors here],
};

export const IDL: SomeProgram = {
  "version": "0.1.0",
  "name": "some_program",
  "instructions": [// Instructions here],
  "accounts:":[// Accounts here],
  "types":[// Custom types here],
  "errors":[//Errors here],
};

After you've validated this is the format, you should just be able to import it in your tests like below and get the type of some account, like this (assuming you want the account type at index 1 inside your idl definition):

import { SomeProgram } from '../target/types/some_program'
let myAccount : SomeProgram['accounts'][1] 

This is called lookup types by the way.