npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codama/dynamic-address-resolution

v0.3.0

Published

Address resolution functionality for instruction accounts in Codama IDLs

Downloads

369

Readme

Codama ➤ Dynamic Address Resolution

npm npm-downloads

This package provides the address resolution functionality for instruction accounts of a Codama IDL. It powers @codama/dynamic-client.

Installation

pnpm install @codama/dynamic-address-resolution

[!NOTE] This package is not included in the main codama package.

Types

  • AccountsInput, ArgumentsInput — user-input shapes for accounts and arguments.
  • ResolverFn, ResolversInput, ResolverFnInput — user-supplied custom resolver functions.
  • AddressInput, PublicKeyLike — accepted address-like inputs (modern Address strings, base58 strings, or legacy PublicKey-like objects with .toBase58()).

Types generation

This package can emit TypeScript the input types required for address resolution of each instruction — ${Name}Args, ${Name}Accounts, ${Name}Resolvers.

CLI

npx @codama/dynamic-address-resolution generate-types <path/to/idl.json> <output-dir>

Writes <idl-name>-address-resolution-types.ts to the output directory.

Programmatic

import { generateTypes } from '@codama/dynamic-address-resolution/codegen';

const source = generateTypes(idl);

Functions

resolveInstructionAccountAddress(input)

Resolves the on-chain Address for a single InstructionAccountNode of an instruction, applying default values, PDA derivation, conditional resolution, and any user-supplied custom resolvers. Returns null for optional accounts that resolve to "omitted".

Untyped:

const address = await resolveInstructionAccountAddress({
    accountsInput: { authority: ownerAddress },
    argumentsInput: { amount: 1_000_000_000n },
    ixAccountNode,
    ixNode,
    root,
});

Typed:

import type { TransferSolAccounts, TransferSolArgs } from './generated/system-program-idl-address-resolution-types';

const address = await resolveInstructionAccountAddress<TransferSolAccounts, TransferSolArgs>({
    accountsInput: { source, destination },
    argumentsInput: { amount: 1_000_000_000n },
    ixAccountNode,
    ixNode,
    root,
});

Automatic resolution rules

Accounts (PDAs, program ids, constants) with a defaultValue are resolved automatically and may be omitted from accountsInput.

| Account scenario | Type in accountsInput | Auto resolution | | --------------------------------------------------------------- | ------------------------------ | -------------------------------------------------------------------------------------------- | | Required account without defaultValue | { system: Address } | No | | Required account with defaultValue(PDA, programId, etc.) | { system?: Address } | Auto-resolved to defaultValue if omitted | | Optional account (isOptional: true)without defaultValue | { system: Address \| null } | Resolved via optionalAccountStrategy,if provided as null | | Optional account (isOptional: true)with defaultValue | { system?: Address \| null } | - null resolves via optionalAccountStrategy- undefined resolves via defaultValue |

Auto-resolved kinds include:

  • PDA accounts — derived from seeds defined in the IDL (pdaValueNode).
  • Program IDs — known program addresses (e.g. System Program, Token Program).
  • ConstantsconstantValueNode defaults.
  • Conditional valuesconditionalValueNode defaults.
  • Custom resolversresolverValueNode defaults supplied via resolversInput.

resolveStandalonePda(root, pdaNode, seedInputs?)

Derives a ProgramDerivedAddress for a PdaNode outside any instruction context — seeds are supplied directly as a Record<string, unknown>.

const pdaNode = root.program.pdas.find(p => p.name === 'metadata')!;
const [pda, bump] = await resolveStandalonePda(root, pdaNode, {
    authority: ownerAddress,
    seed: 'idl',
});

createCodecInputTransformer(typeNode, root, options?)

Returns a function that transforms user-supplied input into the codec-compatible shape expected by @codama/dynamic-codecs — e.g. Uint8Array[encoding, hex].

import { bytesTypeNode } from 'codama';

const transform = createCodecInputTransformer(bytesTypeNode(), root, {
    bytesEncoding: 'base16',
});

transform(new Uint8Array([72, 101, 108, 108, 111]));
// => ['base16', '48656c6c6f']

createDefaultValueEncoderVisitor(codec)

Returns a Visitor<ReadonlyUint8Array> that encodes default ValueNodes.

import { getNodeCodec } from '@codama/dynamic-codecs';
import { bytesValueNode, visit } from 'codama';

const codec = getNodeCodec([root, root.program, argNode]);
const encoder = createDefaultValueEncoderVisitor(codec);
const bytes = visit(bytesValueNode('base16', 'a1b2c3'), encoder);

Helpers

toAddress(input)

Normalizes any AddressInput (modern Address string, base58 string, or legacy PublicKey-like object with .toBase58()) into an Address.

const a1 = toAddress('11111111111111111111111111111111');
const a2 = toAddress(new PublicKey());

isPublicKeyLike(value)

Duck-typed guard for legacy PublicKey objects.

if (isPublicKeyLike(value)) {
    const addr = toAddress(value);
}

isAddressConvertible(value)

Returns true if value is a string Address or a PublicKeyLike object — i.e. safe to pass to toAddress.

if (isAddressConvertible(input)) {
    return toAddress(input);
}

Constants

  • OPTIONAL_NODE_KINDS — type-node kinds treated as optional.