In https://beta.solpg.io/tutorials, pick up the "https://beta.solpg.io/tutorials" demo project.

Here is the demo code I got: https://beta.solpg.io/65aa97e9cffcf4b13384cf03

But it failed to build.

Then I exported it to my local net env to build it. My Cargo.toml's dependencies are: enter image description here

After hours of fixing, there still error that I could not fix.

Error message are:

error[E0432]: unresolved import `anchor_spl::metadata`
 --> programs/anchor-token/src/lib.rs:4:5
4 |     metadata::{create_metadata_accounts_v3, CreateMetadataAccountsV3, Metadata},
  |     ^^^^^^^^ could not find `metadata` in `anchor_spl`

error[E0432]: unresolved imports `mpl_token_metadata::pda`, `mpl_token_metadata::state`
 --> programs/anchor-token/src/lib.rs:7:26
7 | use mpl_token_metadata::{pda::find_metadata_account, state::DataV2};
  |                          ^^^                         ^^^^^ could not find `state` in `mpl_token_metadata`
  |                          |
  |                          could not find `pda` in `mpl_token_metadata`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `anchor-token` due to 2 previous errors

I know bellow import not work. And I can found replacement: mpl_token_metadata::types::DataV2 by google, but don't know how to import others properly.

use anchor_spl::{
    metadata::{create_metadata_accounts_v3, CreateMetadataAccountsV3, Metadata},
use mpl_token_metadata::{pda::find_metadata_account, state::DataV2};

1 Answer 1


I conquer this after days of dipping into anchor and mpl-token-metadata source code.

First, to answer a simple question to myself: playground always use latest version crate. And we can not choose which version of crate to use.

Second, mpl_token_metadata::{pda::find_metadata_account,state::DataV2} only exist in versions before v2.0.0(excludsive).

In latest mpl_token_metadata, there are 'mpl_token_metadata::types::DataV2', but no replacement for find_metadata_account(). So I copy find_metadata_account's code out from older version to my program.

Third, to use anchor_spl::metadata::xx, we must enable "metadata" feature on Cargo.toml's dependencies section. For example: anchor-spl = {version = "0.29.0", features = ["metadata"]}

Finally, here is my version of 'battle-coins' example: https://beta.solpg.io/65ace254cffcf4b13384cf14

  • ok, did you find out what function replaces find_metadata_account? Mar 25 at 17:02
  • Not yet. Haven't got time on it. Mar 26 at 7:19
  • @breezewang thank for you info I saw in your code // // The PDA is both the address of the mint account and the mint authority that mean mint token can call from admin and contract also ? can you explain and have GitHub for test what I need is create contract with token pda account and can call from mint auth and also pda like function modifier in solidity.
    – Peter Jack
    Apr 30 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.