Skip to content

mfactory-lab/ic-solana

Repository files navigation

IC-Solana Gateway for the Internet Computer

Internet Computer portal GitHub license Tests Status

Interact with Solana from the Internet Computer.

This project is a work in progress, and is not yet ready for production use. We are happy to answer questions if they are raised as issues in this GitHub repo.

Overview

IC-Solana is a solution that bridges Solana with the Internet Computer. It allows developers to build decentralized applications (dApps) on the Internet Computer with functionality comparable to traditional Solana dApps. This integration combines the capabilities of both blockchain networks, making it easier to develop cross-chain applications and expand the possibilities for decentralized solutions.

Quick start

Add the following configuration to your dfx.json file (replace the ic principal with any option from the list of available canisters):

{
  "canisters": {
    "solana_rpc": {
      "type": "custom",
      "candid": "https://github.com/mfactory-lab/ic-solana/blob/main/src/ic-solana-rpc/ic-solana-rpc.did",
      "wasm": "https://github.com/mfactory-lab/ic-solana/blob/main/ic-solana-rpc.wasm.gz",
      "init_arg": "(record {})"
    },
    "solana_wallet": {
      "type": "custom",
      "candid": "https://github.com/mfactory-lab/ic-solana/blob/main/src/ic-solana-wallet/ic-solana-wallet.did",
      "wasm": "https://github.com/mfactory-lab/ic-solana/blob/main/ic-solana-wallet.wasm.gz",
      "init_arg": "(record {})"
    }
  }
}

Running the project locally

Requirements

Make sure you have the following installed:

Building the code

Start a local replica listening on port 4943:

# Start a local replica
dfx start --clean --host 127.0.0.1:4943

Build and deploy canisters:

# Deploy the `solana_rpc` canister locally
dfx deploy solana_rpc --argument '(record {})'

# Deploy the `solana_wallet` canister locally
dfx deploy solana_wallet --argument '(record {})'

All the canisters will be deployed to the local network with their fixed canister ids.

Once the build and deployment are complete, your application will be accessible at:

http://localhost:4943?canisterId={asset_canister_id}

Replace {asset_canister_id} with the actual canister's ID generated during deployment.

Examples

# Use Solana mainnet cluster
dfx canister call solana_rpc sol_getHealth '(variant{Mainnet},null)' --wallet $(dfx identity get-wallet) --with-cycles 1000000000

# Use Solana devnet cluster
dfx canister call solana_rpc sol_getHealth '(variant{Devnet},null)' --wallet $(dfx identity get-wallet) --with-cycles 1000000000

# Use single custom RPC
dfx canister call solana_rpc sol_getHealth '(variant{Custom=vec{record{network="https://mainnet.helius-rpc.com/"}}},null)' --wallet $(dfx identity get-wallet) --with-cycles 1000000000

# Use multiple custom RPCs
dfx canister call solana_rpc sol_getHealth '(variant{Custom=vec{record{network="mainnet"},record{network="https://mainnet.helius-rpc.com/"}}},null)' --wallet $(dfx identity get-wallet) --with-cycles 1000000000

# Use single provider RPC (predefined providers: mainnet|m, devnet|d, testnet|t)
dfx canister call solana_rpc sol_getHealth '(variant{Provider=vec{"mainnet"}},null)' --wallet $(dfx identity get-wallet) --with-cycles 1000000000

Components Overview

The RPC Canister enables communication with the Solana blockchain, using HTTPS outcalls to transmit raw transactions and messages via on-chain APIs of Solana JSON RPC providers, for example, Helius or Quicknode.

Key functionalities include:

  1. Retrieving Solana-specific data, such as block details, account information, node statistics, etc.
  2. Managing Solana RPC providers, including registration, updates, and provider configurations.
  3. Calculating and managing the cost of RPC requests.

The Wallet Canister is used for managing addresses and for securely signing transactions/messages for the Solana blockchain using the threshold Schnorr API.

Key functionalities include:

  1. Generating a Solana public key (Ed25519) for a user on the Internet Computer (ICP).
  2. Signing messages using distributed keys based on the Threshold Schnorr protocol.
  3. Signing and sending raw transactions to the Solana blockchain via the RPC Canister.

A Rust library that provides the necessary tools for integrating Solana with ICP canisters.

Access control

The Solana RPC canister stores a list of registered Solana JSON RPC providers, to which transactions and messages can be submitted. Access to the list is controlled by admin(s) who can assign managers with specific rights to add, remove, and update Solana JSON RPC providers.

Reproducible builds

The SOLANA RPC canister supports reproducible builds:

  1. Ensure Docker is installed on your machine.
  2. Run ./scripts/docker-build --rpc in your terminal.
  3. Run sha256sum ic-solana-rpc.wasm.gz on the generated file to view the SHA-256 hash.

Compare the generated SHA-256 hash with the hash provided in the repository to verify the build's integrity.

Learn more

To learn more about the SOLANA RPC Canister and its integration with Solana and ICP, explore the following resources:

Contributing

Contributions are welcome! Please check out the contributor guidelines for more information.

License

This project is licensed under the Apache License 2.0.