/ic-alloy-toolkit

Example code for using Alloy with the Internet Computer.

Primary LanguageTypeScriptMIT LicenseMIT

Alloy + ICP Toolkit

Alloy is the next generation of Ethereum support libraries, written in Rust and designed for scalability and performance. Alloy is a rewrite of of ethers-rs from the ground up. Alloy includes built in support for transports like HTTP, WebSockets and IPC.

Alloy now also works with the Internet Computer (ICP)!

The Alloy libraries have been forked to add support for ICP as a transport layer. This makes it possible to use the full feature set of Alloy from ICP canisters.

This repository contains a collection of examples of how to use Alloy in an IC context.

Contributors Forks Stargazers Issues MIT License

screenshot

Example, get the balance of an address

#[ic_cdk::update]
async fn get_balance(address: String) -> Result<String, String> {
    let address = address.parse::<Address>().map_err(|e| e.to_string())?;
    let rpc_service = RpcService::EthSepolia(EthSepoliaService::Alchemy);
    let config = IcpConfig::new(rpc_service);
    let provider = ProviderBuilder::new().on_icp(config);
    let result = provider.get_balance(address).await;

    match result {
        Ok(balance) => Ok(balance.to_string()),
        Err(e) => Err(e.to_string()),
    }
}

get_balance.rs

Example, sign a message

#[ic_cdk::update]
async fn sign_message(message: String) -> Result<String, String> {
    let ecdsa_key_name = "key_1".to_string();
    IcpSigner::new(vec![], &ecdsa_key_name, None)).await.unwrap();
    let signature = signer.sign_message(message.as_bytes()).await.unwrap();
    Ok(format!("{:?}", signature))
}

sign_message.rs

Setup

There are two main ways to set up and run the project:

1. Using a VS Code Dev Container

The dev containers extension lets you use a Docker container as a full-featured development environment. This repository includes a dev container configuration that you can use to open the project with all the necessary tools and dependencies pre-installed.

Pre-requisites:

Once Docker, Visual Studio Code and the Dev Containers Extension are installed, you can open the project in a container by clicking the button below:

Open locally in Dev Containers

2. Setup manually

Pre-requisites:

Once you have the prerequisites installed, you can clone this repository and run the project.

Running the project

1. Start the Internet Computer

dfx start --background

2. Install dependencies

pnpm install

3. Deploy the canisters

dfx deploy

Develop

During development, you can run the frontend with hot reloading using Vite.

pnpm run dev

Collaborators

kristoferlund
Kristofer
domwoe
Dominic Wörner

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.