Helios is a fully trustless, efficient, and portable Ethereum light client written in Rust.
Helios converts an untrusted centralized RPC endpoint into a safe unmanipulable local RPC for its users. It syncs in seconds, requires no storage, and is lightweight enough to run on mobile devices.
This Swift Package is a wrapper around Helios' Rust library.
Add the package declaration to your project's manifest dependencies array:
.package(url: "https://github.com/rkreutz/HeliosKit.git", from: "0.1.0")
You can start a client with:
let rpcURL = // URL to the unsafe RPC
try await Helios.shared.start(rpcURL: rpcURL)
Have in mind that only one client can be running at all times.
Once the client is up and running you can start doing RPC calls to it, it will be listening to 127.0.0.1:8545
.
You may also use the library to call methods from the RPC with:
let (data, _) = try await Helios.shared.call(method: "eth_getBalance", params: ["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"])
let response = String(data: data, encoding: .utf8)!
print(response) // {"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000000","id":...}
To shutdown your client gracefully, use the shutdown()
method:
await Helios.shared.shutdown()
You may enable logging of the Rust lib with an environment var at runtime (RUST_LOG
). The library uses Rust's env_logger
framework, so you may set the desired levels accordingly.
There is a build_xcframework.sh
script in the repo which can be used to build the xcframework
for the helios rust library, this will create the XCFramework and place it (along with the Swift bridging files and checksum) in the .build/helios-rs/build
directory. You may specify which version you would like to build and provide an additional parameter to the script to build a debug
or release
framework.
> zsh build_xcframework.sh 0.1.3 debug # .build/helios-rs/build/0.1.3/debug/helios.xcframework
> zsh build_xcframework.sh 0.1.3 # .build/helios-rs/build/0.1.3/debug/helios.xcframework
> zsh build_xcframework.sh debug # No version specified, defaults to latest
> zsh build_xcframework.sh # No version specified, defaults to latest
To be able to compile the test target you must create a Config.swift
file (you can just copy and rename Config.swift.example
) and add the RPC URL you have for mainnet.
You may optionaly provide a rawTransaction
data to test sendRawTransaction(_:)
.