Here is an article summarizing the issue:

Error: “Argument of type ‘PublicKey’ is not assignable to parameter of type ‘Provider'” in Solana Program

When running a test script on a Solana program using the Anchor framework, you can encounter an error that seems impossible to resolve. The specific error message is:

“Argument of type ‘PublicKey’ is not assignable to parameter of type ‘Provider'”

This error occurs when attempting to run an Anchor test script on a Solana program that uses the treasury_toolkit library.

What causes this error?

The issue arises from the fact that the treasury_toolkit library provides two types: Provider and PublicKey. However, in the context of a Solana program, it is not clear which type to use. The Provider class is used for interacting with external services, while PublicKey is used to represent addresses.

How to resolve this error

Solana: Error:

To resolve this error, you need to identify where the treasury_toolkit library is being imported and ensure that you are using the correct types. Here’s a step-by-step solution:

  • Check your imports: Inspect your code to see where the treasury_toolkit library is being imported. Make sure it is importing the correct type, either Provider or PublicKey.

  • Use the correct type in Anchor test scripts

    : In Anchor tests, you need to use the treasury_toolkit.Payer interface instead of Provider. This is because Provider is specific to Solana’s RPC interface.

  • Update your code: Update all instances of Provider to use treasurer_toolkit.Payer.

Example updated import

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

becomes

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

import { treasury_toolkit as treasuries } 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 “Argument of type ‘PublicKey’ is not assignable to parameter of type ‘Provider'” error and successfully run your test script on your Solana program.