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:
-
Add patch overrides
Copy the[patch.crates-io]section from the top-levelCargo.tomlfile in thedfinity/sol-rpcrepository into your ownCargo.toml.
This is necessary because the Solana SDK’swasm32-unknown-unknowntarget assumes a browser environment and depends onwasm-bindgen, which is incompatible with canister environments.
See this issue for more details. -
Override
getrandomfeatures
Add the following to yourCargo.tomlfile:= { = "*", = ["custom"] }This ensures that the
getrandomcrate (a transitive dependency of the Solana SDK) does not pull inwasm-bindgen, which is incompatible with canister environments.💡 You can also specify an exact version of
getrandom, as long as thecustomfeature is enabled, e.g.getrandom = { version = "0.2.14", features = ["custom"] }.For more information, see this blog post.
-
macOS-specific LLVM setup
On macOS, anllvmversion that supports thewasm32-unknown-unknowntarget is required. This is because thezstdcrate (used, for example, to decodebase64+zstd-encoded responses from Solana'sgetAccountInfo) depends on LLVM during compilation. The default LLVM bundled with Xcode does not supportwasm32-unknown-unknown. To fix this:- Install the Homebrew version of LLVM:
- Create a top-level
.cargo/config.tomlfile in your project (or modify the existing one) and add the following entries:
Where you need to replace[] ="<LLVM_PATH>/bin/llvm-ar" ="<LLVM_PATH>/bin/clang"<LLVM_PATH>with the output of the following command:
- Install the Homebrew version of LLVM: