react-native-helios
v0.1.22
Published
A cross-platform trustless Ethereum light client for React Native.
Downloads
295
Readme
react-native-helios
⚠️ Currently
react-native-helios
only supports execution on iOS, MacOS, Android and Expo.
Throughout the majority of Ethereum's history, frontend applications have been forced to rely upon centralized interfaces like Infura to access the decentralized network. This is because to act as a meaningful participant to the network, such as an entity capable of submitting transactions or maintaining a verifiable history the network state, the protocol's current design demands high device specifications that are insurmountable for even top-end mobile devices.
This reliance on third party infrastructure typically aided the delivery of ethereum frontend applications, but is subject to the pitfalls of all centralized systems; susceptibility to downtime and subservience to censorship and monetization.
Introducing helios
! 👋
Helios is an innovative new light client for Ethereum which is minimal enough to run on mobile devices or even from within React Native applications.
The key property enabled by helios
, compared to traditional light clients, is the level of trustlessness.
Where contemporary light clients merely defer responsibility to a more powerful node, helios
is capable of maintaining the state of the decentralized network autonomously by inferring the validity of the chain header by assessing the validity of the proof sequence that constitutes the canonical chain.
Much like the proposed design of the Portal Network, helios
need only trust a potentially untrustworthy block header proof provider just once in order to quickly synchronize with canonical Ethereum chain, verify it's validity, and transact as an independent network participant.
react-native-helios
⚛️
react-native-helios
is a React Native wrapper for helios
:
yarn add react-native-helios
To instantiate a trustless JSON-RPC, we merely need to call the start()
method:
import { start, StartParams } from 'react-native-helios';
const params: StartParams = {
untrusted_rpc_url:
'https://eth-mainnet.g.alchemy.com/v2/<your-alchemy-key>', // source of initial proofs
consensus_rpc_url: 'https://www.lightclientdata.org',
};
const { shutdown } = await start(params);
console.log("Ready!");
// ...
await shutdown();
This will establish a JSON-RPC on your device running at http://127.0.0.1:8485
, which can then be interacted like usual using ethers
:
import { Platform } from 'react-native';
import { ethers } from 'ethers';
import { getHeliosProvider } from 'react-native-helios';
const provider = getHeliosProvider(params);
const [blockNumber, balance] = await Promise.all([
provider.getBlockNumber(),
provider.getBalance('cawfree.eth'),
]);
console.log(
`Block number is: ${blockNumber} and balance is ${ethers.utils.formatEther(
balance
)}Ξ!`
);
You can also define a weak subjectivity checkpoint
using the checkpoint
parameter of StartParams
. If you're unsure of a value to use, you can use: fallbackCheckpoint(network: Network)
:
import { fallbackCheckpoint, start } from 'react-native-helios';
const params: StartParams = {...};
const checkpoint = await fallbackCheckpoint(params);
await start({ ...params, checkpoint: fallbackCheckpoint });
Warning
If a
checkpoint
is not manually specified, thefallbackCheckpoint
will be used. Please be aware of the potential dangers in the implicit trust assumptions of doing so.
Building from source 🏗
Note Currently,
react-native-helios
may only be compiled on Apple Silicon.
- Make sure you've installed
rustup
:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Clone and build
react-native-helios
:
git clone https://github.com/cawfree/react-native-helios
cd react-native-helios
yarn ; yarn heliosup
For iOS, we leverage
swift-bridge
andcargo-lipo
to automatically generate a Swift-compatible Native Module which bridges into the original Rust client. To support thearm64
architecture for both simulated and physical iOS devices, the target-specific static libraries are repackaged into anXCFramework
.For Android, we use
flapigen
andrifgen
to synthesize a runtime-compatible interface. Currently, only the build architecturesarm64_v8a
andx86_64
are supported.
- Finally, run the Example Project.
Building with Expo 📲
- You can install to your project using
npx expo install react-native-helios
. - Next, you'll need to add the Helios plugin to your Expo config (
app.json
,app.config.json
orapp.config.js
):
{
"expo": {
"name": "my-app",
+ "plugins": [
+ "react-native-helios"
+ ]
}
}
- Once that's done, use
npx expo prebuild
to generate Expo-friendly native binaries. - Finally, run
eas build
to build a new binary, or useyarn ios
oryarn android
to start running.
Note: To run
eas build
, you'll need tonpm install --global expo-cli eas-cli
.