You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3ed69d8
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: packages/dynamic-address-resolution/README.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,11 +88,12 @@ When no branch matches, optional accounts resolve using the optional account str
88
88
89
89
## `resolveStandalonePda(input)`
90
90
91
-
Derives a PDA outside of any instruction, from its path and the values of its variable seeds.
91
+
Derives a PDA outside of any instruction, from its path and the values of its variable seeds. It uses the given `programId`, or else the `programId` of the PDA, or else the address of the program defining it. Pass a `programId` for PDAs that instructions derive from another program through their `pdaValueNode.programId`.
This package provides a runtime Solana program client to dynamically interact with Solana programs using Codama IDLs — with optional TypeScript type generation for full type safety. It contains PDA derivation, and an instruction builder powered by [@codama/dynamic-instructions](../dynamic-instructions/README.md).
10
+
This package provides a runtime Solana program client to dynamically interact with Solana programs using Codama IDLs, with optional TypeScript type generation for full type safety. It contains PDA derivation, and an instruction builder powered by [@codama/dynamic-instructions](../dynamic-instructions/README.md).
11
11
12
12
## Installation
13
13
@@ -42,14 +42,20 @@ import type { MyProgramClient } from './generated/my-program-types';
// client.methods, .accounts(), args are now fully typed
45
+
// client.methods, their data and .accounts() are now fully typed
46
46
```
47
47
48
48
## API Reference
49
49
50
50
### `createProgramClient<T>(idl, options?)`
51
51
52
-
Creates a program client from a Codama IDL.
52
+
Creates a program client from a Codama IDL of the latest major. IDLs of older majors (e.g. v1) throw `CODAMA_ERROR__VERSION_MISMATCH`, so upgrade them first with [`@codama/upgrade`](../upgrade):
.myInstruction(args) // provide instruction arguments
81
-
.accounts(accounts) // provide account addresses
83
+
.myInstruction(data) // provide the instruction data
84
+
.accounts(accounts) // provide account addresses, including remaining accounts
82
85
.signers(['accountName']) // optionally mark ambiguous accounts as signers
83
-
.resolvers({ customResolver: async (argumentsInput, accountsInput) => {} }) // optionally provide custom resolver according to resolverValueNode in IDL
84
86
.instruction(); // Promise<Instruction>
85
87
```
86
88
@@ -121,19 +123,23 @@ When an account has `isSigner: 'either'` in the IDL, use `.signers()` to explici
121
123
.signers(['owner'])
122
124
```
123
125
124
-
### Custom resolvers
126
+
### Remaining accounts
125
127
126
-
When an account or argument is `resolverValueNode` in the IDL, provide a custom resolver function `.resolvers({ [resolverName]: async fn })` to help with account/arguments resolution:
128
+
Remaining accounts are provided in `.accounts()` as lists of addresses, under the name of their `remainingAccountsNode`:
Accounts and data fields resolved by custom code, i.e. those carrying a `codama.resolver` plugin, have no default value the client can compute. Provide them like any other input (or `null` when they are optional accounts):
PDAs are derived from the `programId` of the PDA, or else the program defining it. Instructions may derive a PDA from another program (`pdaValueNode.programId`); pass that program as `programId` to derive it the same way:
Accounts with `pdaValueNode` defaults are resolved automatically. Seeds are pulled from other accounts and arguments in the instruction:
164
+
Accounts with `pdaValueNode` defaults are resolved automatically. Seeds are pulled from other accounts and data fields of the instruction:
153
165
154
166
```ts
155
167
// metadata PDA is auto-derived from program + seed
@@ -161,9 +173,9 @@ const ix = await client.methods
161
173
162
174
Nested/dependent PDAs (where one PDA seed references another PDA) are resolved recursively.
163
175
164
-
## Arguments
176
+
## Data
165
177
166
-
Arguments with `defaultValueStrategy: 'omitted'` (e.g., discriminators) are auto-encoded and should not be provided.
178
+
The instruction data is provided as the value of its `data` type node, e.g. an object keyed by field identifier for a `structTypeNode`. Fields with `defaultValueStrategy: 'omitted'` (e.g. discriminators) are encoded automatically and should not be provided.
167
179
168
180
## Error Handling
169
181
@@ -183,7 +195,7 @@ try {
183
195
184
196
## CLI
185
197
186
-
The package includes a CLI for generating TypeScript types from Codama IDL files.
198
+
The package includes a CLI for generating TypeScript types from Codama IDL files of the latest major.
This reads the IDL file and writes a `*-types.ts` file to the output directory containing strongly-typed interfaces for all instructions, accounts, arguments, PDAs, and the program client.
210
+
This reads the IDL file and writes a `*-types.ts` file to the output directory containing strongly-typed interfaces for all instruction data, accounts, PDAs, and the program client.
0 commit comments