sol_rpc_client 2.0.0

Client to interact with the SOL RPC canister
Documentation

Internet Computer portal DFinity Forum GitHub license

Crate sol_rpc_client

Library to interact with the SOL RPC canister from a canister running on the Internet Computer. See the Rust documentation for more details.

Build Requirements

If you are using the sol_rpc_types crate inside a canister, make sure to follow these steps to ensure your code compiles:

  1. Add patch overrides
    Copy the [patch.crates-io] section from the top-level Cargo.toml file in the dfinity/sol-rpc repository into your own Cargo.toml.
    This is necessary because the Solana SDK’s wasm32-unknown-unknown target assumes a browser environment and depends on wasm-bindgen, which is incompatible with canister environments.
    See this issue for more details.

  2. Override getrandom features
    Add the following to your Cargo.toml file:

    getrandom = { version = "*", features = ["custom"] }
    

    This ensures that the getrandom crate (a transitive dependency of the Solana SDK) does not pull in wasm-bindgen, which is incompatible with canister environments.

    💡 You can also specify an exact version of getrandom, as long as the custom feature is enabled, e.g. getrandom = { version = "0.2.14", features = ["custom"] }.

    For more information, see this blog post.

  3. macOS-specific LLVM setup
    On macOS, an llvm version that supports the wasm32-unknown-unknown target is required. This is because the zstd crate (used, for example, to decode base64+zstd-encoded responses from Solana's getAccountInfo) depends on LLVM during compilation. The default LLVM bundled with Xcode does not support wasm32-unknown-unknown. To fix this:

    • Install the Homebrew version of LLVM:
      brew install llvm
      
    • Create a top-level .cargo/config.toml file in your project (or modify the existing one) and add the following entries:
      [env]
      AR="<LLVM_PATH>/bin/llvm-ar"
      CC="<LLVM_PATH>/bin/clang"
      
      Where you need to replace <LLVM_PATH> with the output of the following command:
      brew --prefix llvm