6

I am using OSX with the following packages:

  • Anchor CLI 0.28.0
  • Rust 1.70.0
  • Solana CLI 1.16.1

To flush cache and ensure my environment is clean I have run:

anchor clean && cargo update

These are my project dependencies:

[dependencies]
anchor-lang = { version = "0.28.0", features = ["init-if-needed"] }
anchor-spl = { version = "0.28.0", features = ["metadata"] }
solana-program = "1.14.19"
mpl-token-metadata = { version = "1.12.0", features = ["no-entrypoint"] }

But when I run anchor build, it throws multiple errors like the following:


error[E0277]: the trait bound `Pubkey: BorshSerialize` is not satisfied
  --> src/idl.rs:35:10
   |
35 | #[derive(AnchorSerialize, AnchorDeserialize)]
   |          ^^^^^^^^^^^^^^^ the trait `BorshSerialize` is not implemented for `Pubkey`
   |
   = help: the following other types implement trait `BorshSerialize`:
             &T
             ()
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0, T1, T2, T3, T4, T5, T6)
           and 81 others

This is the Cargo.lock file showing the anchor-lang installed dependencies:

[[package]]
name = "anchor-lang"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d2d4b20100f1310a774aba3471ef268e5c4ba4d5c28c0bbe663c2658acbc414"
dependencies = [
 "anchor-attribute-access-control",
 "anchor-attribute-account",
 "anchor-attribute-constant",
 "anchor-attribute-error",
 "anchor-attribute-event",
 "anchor-attribute-program",
 "anchor-derive-accounts",
 "anchor-derive-space",
 "arrayref",
 "base64 0.13.1",
 "bincode",
 "borsh 0.10.3",
 "bytemuck",
 "getrandom 0.2.10",
 "solana-program",
 "thiserror",
]

Seems like anchor-lang is using a conflicting borsh version 0.10.3 when it should be using 0.9.3. Does anyone know a workaround to fix this issue?

2 Answers 2

8

This error is resulting from the latest solana-program and mpl-token-metadata crates being incompatible with each other due to different borsh versions.

The fix is simple, without making any changes to your Cargo.toml:

cargo update -p solana-zk-token-sdk --precise 1.14.19
cargo update -p [email protected] --precise 0.9.3

Seems like anchor-lang is using a conflicting borsh version 0.10.3 when it should be using 0.9.3

There is nothing conflicting there, you are able to use both 0.9 and 0.10 versions as well as 1.14 and 1.16 versions of Solana crates. Without that range specification, there would be no way of compiling crates such as mpl-token-metadata 1.12.0 which uses borsh 0.9.3 when the solana-program 1.16.0 crate uses borsh 0.10.3.

For a longer explanation see this comment.

2
  • 1
    Thanks @acheron! Do you know if there is a way to achieve the same: solana-zk-token-sdk==1.14.19 and [email protected]==0.9.3 but within the Cargo.toml file instead of using additional cargo update commands? For instance using [patch.crates-io]?
    – Ander
    Jun 27 at 22:05
  • I also need an alternative, because when publishing my package on crates.io using cargo publish, same error is displayed. Is there any other way instead of using cargo update -p ... to make dependencies work also with cargo publish? Jun 28 at 1:12
1

For anyone else who'll be trying work on a native Solana program, here is a set-up that works...

My Solana cli suite solana-cli 1.16.4 (src:4ce8fe76; feat:2891131721, client:SolanaLabs)

Cargo.toml packages

cargo add solana-program@=1.14.19
cargo add [email protected]
cargo add [email protected]
cargo add [email protected] --features=no-entrypoint
cargo add [email protected] --features=no-entrypoint
cargo add [email protected] --features=no-entrypoint

Your Answer

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

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