Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[TypeScript] `ViemWalletProvider` rejects a wallet client from a newer viem than the exactly pinned one (TS2345, `tokens` missing on `Client`)

Aperta Adatta ai principianti
#1,532 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
tooling

Direzione di ricerca

Inizia da typescript/agentkit/package.json ed esamina le impostazioni della dipendenza e della peer dependency di viem. Riproduci il problema con il typecheck.ts fornito e una versione più recente di viem, quindi verifica che la configurazione delle dipendenze consenta di eseguire il typecheck del client del progetto senza cast e che il caso di controllo con la versione bloccata continui a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Language Affected
  • Python
  • TypeScript
Describe the bug

@coinbase/agentkit depends on viem with an exact version ("viem": "2.38.3" in 0.10.4). A project that uses a newer viem (2.57.2 here) gets two copies of viem: its own at the top level, and AgentKit's pinned one under node_modules/@coinbase/agentkit/node_modules/viem. Viem's Client types are not structurally compatible across these two copies, so a wallet client created in the project does not typecheck as the argument of new ViemWalletProvider(...). Passing a viem wallet client is the constructor's only argument, so a TypeScript project on a newer viem hits this, and the options are to pin the project's viem to AgentKit's exact version or to cast.

Reproduction (no network needed, this is type-level only)

npm init -y
npm i @coinbase/[email protected] [email protected] typescript@5

tsconfig.json:

{ "compilerOptions": { "target": "ES2022", "module": "NodeNext", "moduleResolution": "NodeNext", "strict": true, "noEmit": true, "skipLibCheck": true }, "include": ["typecheck.ts"] }

typecheck.ts:

import { ViemWalletProvider } from "@coinbase/agentkit";
import { createWalletClient, http } from "viem";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { foundry } from "viem/chains";

const walletProvider = new ViemWalletProvider(
  createWalletClient({
    account: privateKeyToAccount(generatePrivateKey()),
    chain: foundry,
    transport: http(),
  }),
);

npx tsc --noEmit -p . fails (tsc 5.9.3). First line and last line of the error (full output below):

typecheck.ts(7,3): error TS2345: Argument of type '{ account: { address: `0x${string}`; nonceManager?: NonceManager | undefined; sign: ...
...
                            Property 'tokens' is missing in type 'Client' but required in type 'Client_Base<Transport, Chain | undefined, Account | undefined, undefined, Tokens | undefined>'.

The chain of "incompatible" properties goes account -> nonceManager -> consume -> client and ends in Client of AgentKit's viem (node_modules/@coinbase/agentkit/node_modules/viem/_types/clients/createClient) lacking the tokens member that the project's viem 2.57.2 has.

Full tsc output
typecheck.ts(7,3): error TS2345: Argument of type '{ account: { address: `0x${string}`; nonceManager?: NonceManager | undefined; sign: (parameters: { hash: `0x${string}`; }) => Promise<`0x${string}`>; signAuthorization: (parameters: AuthorizationRequest) => Promise<...>; ... 5 more ...; type: "local"; }; ... 43 more ...; extend: <const client extends { ...; } & Exac...' is not assignable to parameter of type '{ account: Account | undefined; batch?: { multicall?: boolean | { batchSize?: number | undefined; deployless?: boolean | undefined; wait?: number | undefined; } | undefined; } | undefined; ... 38 more ...; extend: <const client extends { ...; } & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>...'.
  Types of property 'account' are incompatible.
    Type '{ address: `0x${string}`; nonceManager?: NonceManager | undefined; sign: (parameters: { hash: `0x${string}`; }) => Promise<`0x${string}`>; signAuthorization: (parameters: AuthorizationRequest) => Promise<...>; ... 5 more ...; type: "local"; }' is not assignable to type 'Account | undefined'.
      Type '{ address: `0x${string}`; nonceManager?: NonceManager | undefined; sign: (parameters: { hash: `0x${string}`; }) => Promise<`0x${string}`>; signAuthorization: (parameters: AuthorizationRequest) => Promise<...>; ... 5 more ...; type: "local"; }' is not assignable to type '{ address: `0x${string}`; nonceManager?: NonceManager | undefined; sign?: ((parameters: { hash: `0x${string}`; }) => Promise<`0x${string}`>) | undefined; signAuthorization?: ((parameters: AuthorizationRequest) => Promise<...>) | undefined; ... 19 more ...; isDeployed?: undefined; }'.
        Types of property 'nonceManager' are incompatible.
          Type 'import("<project>/node_modules/viem/_types/utils/nonceManager", { with: { "resolution-mode": "import" } }).NonceManager | undefined' is not assignable to type 'import("<project>/node_modules/@coinbase/agentkit/node_modules/viem/_types/utils/nonceManager").NonceManager | undefined'.
            Type 'import("<project>/node_modules/viem/_types/utils/nonceManager", { with: { "resolution-mode": "import" } }).NonceManager' is not assignable to type 'import("<project>/node_modules/@coinbase/agentkit/node_modules/viem/_types/utils/nonceManager").NonceManager'.
              Types of property 'consume' are incompatible.
                Type '(parameters: FunctionParameters & { client: import("<project>/node_modules/viem/_types/clients/createClient", { with: { "resolution-mode": "import" } }).Client; }) => Promise<...>' is not assignable to type '(parameters: FunctionParameters & { client: import("<project>/node_modules/@coinbase/agentkit/node_modules/viem/_types/clients/createClient").Client; }) => Promise<...>'.
                  Types of parameters 'parameters' and 'parameters' are incompatible.
                    Type 'FunctionParameters & { client: import("<project>/node_modules/@coinbase/agentkit/node_modules/viem/_types/clients/createClient").Client; }' is not assignable to type 'FunctionParameters & { client: import("<project>/node_modules/viem/_types/clients/createClient", { with: { "resolution-mode": "import" } }).Client; }'.
                      Type 'FunctionParameters & { client: Client; }' is not assignable to type '{ client: Client; }'.
                        Types of property 'client' are incompatible.
                          Type 'import("<project>/node_modules/@coinbase/agentkit/node_modules/viem/_types/clients/createClient").Client' is not assignable to type 'import("<project>/node_modules/viem/_types/clients/createClient", { with: { "resolution-mode": "import" } }).Client'.
                            Property 'tokens' is missing in type 'Client' but required in type 'Client_Base<Transport, Chain | undefined, Account | undefined, undefined, Tokens | undefined>'.

Control: with npm i [email protected] (the version AgentKit pins) the two copies dedupe and the same file typechecks with exit code 0.

npm ls for the failing install shows the two copies: [email protected] at the top level and [email protected] nested under @coinbase/agentkit.

Expected: a viem client created from a compatible newer viem is accepted by ViemWalletProvider without casting.

Pin on current main (read from the source, not run): typescript/agentkit/package.json on main (2e6dbaf, version 0.11.0, not yet published to npm) still pins viem exactly, now to 2.47.4 (line 75 under dependencies), and has no peerDependencies. The latest npm release is 0.10.4 (2.38.3). I did not test 2.47.4 against 2.57.2.

Possible fix: treat viem as a peer dependency with a range (for example "peerDependencies": { "viem": "^2.38.3" }, possibly with peerDependenciesMeta if some users do not use the viem wallet providers), so a project and AgentKit share one copy. At minimum, a caret range for the regular dependency lets package managers dedupe within the 2.x line. The ViemWalletProvider constructor type could also be loosened, but a shared copy is the more robust fix. I did not check whether other viem-typed public signatures (for example getPublicClient()) are affected the same way.

I am happy to open a PR for the peer dependency change if that direction is acceptable.

Versions
$ node --version
v24.21.0
$ npm list @coinbase/agentkit viem typescript
├── @coinbase/[email protected]
├── [email protected]
└── [email protected]

Related, not duplicates: #332 (install only the dependencies of enabled providers) and #272 (expose viem client actions from ViemWalletProvider) touch the same area; I found no open or closed issue or PR about the viem version pin.

Lingua principale
TypeScript
Stelle
1.3k
Fork
857
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di coinbase/agentkit

Tutte le issue di coinbase/agentkit

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.