react-native-helios
TypeScript icon, indicating that this package has built-in type declarations

0.1.22 • Public • Published

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.

❯ Learn more

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, the fallbackCheckpoint 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.

  1. Make sure you've installed rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. 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 and cargo-lipo to automatically generate a Swift-compatible Native Module which bridges into the original Rust client. To support the arm64 architecture for both simulated and physical iOS devices, the target-specific static libraries are repackaged into an XCFramework.

For Android, we use flapigen and rifgen to synthesize a runtime-compatible interface. Currently, only the build architectures arm64_v8a and x86_64 are supported.

  1. Finally, run the Example Project.

Building with Expo 📲

  1. You can install to your project using npx expo install react-native-helios.
  2. Next, you'll need to add the Helios plugin to your Expo config (app.json, app.config.json or app.config.js):
{
  "expo": {
    "name": "my-app",
+   "plugins": [
+     "react-native-helios"
+   ]
  }
}
  1. Once that's done, use npx expo prebuild to generate Expo-friendly native binaries.
  2. Finally, run eas build to build a new binary, or use yarn ios or yarn android to start running.

Note: To run eas build, you'll need to npm install --global expo-cli eas-cli.

License ✌️

MIT

Package Sidebar

Install

npm i react-native-helios

Weekly Downloads

85

Version

0.1.22

License

MIT

Unpacked Size

88.9 MB

Total Files

73

Last publish

Collaborators

  • cawfree