Core Contract Interactions
The Karak Offchain SDK uses Alloy.rs for low-level contract interactions but includes custom wrappers on top to simplify working with Karak core contracts. These wrappers make it easier for developers to integrate with the Karak ecosystem, streamlining the development of Distributed Secure Services (DSSs).
Using the sol!
macro we have pre-built the Karak Core contracts instance which is available as karak_contracts::Core
.
Example Usage
You can use keystone contract addresses to instantiate the contract instance.
use std::str::FromStr;
use alloy::network::EthereumWallet;
use alloy::primitives::Address;
use alloy::signers::local::PrivateKeySigner;
use alloy::providers::ProviderBuilder;
use eyre::Result;
use karak_contracts::Core;
async fn get_core_version() -> Result<String> {
let signer: PrivateKeySigner = "<PRIVATE_KEY>".parse().expect("should parse private key");
let wallet = EthereumWallet::from(signer.clone());
let rpc_url = "<RPC_URL>".parse().expect("should parse rpc_url");
let provider = ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_http(rpc_url);
let core = Core::new(Address::from_str("<Address_Of_Core>")?, provider);
// Using this core instance you can call any function on core eg:
Ok(core.VERSION().call().await.unwrap()._0)
}
Note: We recommend using Alloy.rs for all contract interactions.