Skip to content

rksperax/react-native-web3-kit

Repository files navigation

react-native-web3-kit

CI npm version License: MIT TypeScript

Lightweight Web3 utilities for React Native wallets and DeFi apps. Zero native dependencies — safe to use in Expo and bare React Native projects.

Built by Rajan Kumar · Senior Frontend Developer · React Native · Web3

Install

npm install react-native-web3-kit
# or
yarn add react-native-web3-kit

Features

  • Address helpers — validate, shorten, and compare EVM addresses
  • Amount formatting — gwei ↔ ETH conversion, wei parsing
  • Chain metadata — Ethereum, Polygon, Arbitrum, Base explorers & RPC URLs
  • App state hook — reconnect wallet/RPC when app returns to foreground

Usage

Address formatting

import { formatAddress, isValidAddress } from "react-native-web3-kit";

if (isValidAddress(userInput)) {
  console.log(formatAddress(userInput)); // 0x742d...f44e
}

ETH / gwei conversion

import { gweiToEth, parseEthToWei } from "react-native-web3-kit";

gweiToEth(1_500_000_000n); // "1.5"
parseEthToWei("0.25");     // 250000000000000000n

Block explorer links

import { getExplorerTxUrl } from "react-native-web3-kit";

getExplorerTxUrl(1, "0xabc..."); // https://etherscan.io/tx/0xabc...

Wallet reconnect on app resume (React Native)

import { AppState } from "react-native";
import { useAppStateReconnect } from "react-native-web3-kit";

function WalletProvider({ children }) {
  useAppStateReconnect(async () => {
    await reconnectWallet();
  }, { AppState });

  return children;
}

API

Export Description
isValidAddress Validate EVM address format
formatAddress Shorten address for UI
addressesEqual Case-insensitive address compare
gweiToEth Convert gwei bigint to ETH string
parseEthToWei Parse decimal ETH to wei
formatTxHash Shorten transaction hash
CHAINS Common chain metadata
getChainById Lookup chain by ID
getExplorerAddressUrl Block explorer address URL
getExplorerTxUrl Block explorer tx URL
useAppStateReconnect Reconnect callback on foreground

Development

npm install
npm test
npm run build

Contributing

Issues and PRs welcome! See CONTRIBUTING.md.

License

MIT © Rajan Kumar

About

Lightweight Web3 utilities for React Native wallets and DeFi apps

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors