RainbowKit Documentation
repository·main·Indexed 25 days ago
https://github.com/rainbow-me/rainbowkitA React library designed to simplify wallet connection in decentralized applications (dapps). RainbowKit provides out-of-the-box wallet management and is built on top of wagmi and viem.
What's inside RainbowKit
- RainbowKit is a React library designed to simplify adding wallet connection functionality to decentralized applications (dapps). It provides an intuitive, responsive, and highly customizable interface for users to connect their wallets.
Understand the ERC-6909 Minimal Multi-Token Interface
mainERC-6909 is a minimal multi-token interface designed to allow a single contract to manage multiple token IDs. It provides a set of interfaces that can be implemented to support different levels of functionality, ranging from basic transfers to advanced metadata and supply tracking.Explore OpenZeppelin Utilities
mainOpenZeppelin provides a variety of miscellaneous contracts and libraries to improve security, manage new data types, and safely use low-level primitives in Solidity. Key categories include:
- Math: Arithmetic functions (
Math,SignedMath) and checked downcasting (SafeCast). - Cryptography: Signature handling (
ECDSA,P256,RSA,SignatureChecker), hashing (Hashes,MerkleProof), and typed data (EIP712). - Security: Reentrancy protection (
ReentrancyGuard,ReentrancyGuardTransient), emergency pausing (Pausable), and nonce management (Nonces,NoncesKeyed). - Introspection: Interface inspection via
ERC165andERC165Checker. - Data Structures: Efficient storage and management using
BitMaps,EnumerableMap,EnumerableSet,DoubleEndedQueue,CircularBuffer,Checkpoints,Heap, andMerkleTree. - Low-level & Formatting: Utilities for
Address,Arrays,Base64,Bytes,Calldata,Strings,ShortStrings,SlotDerivation,StorageSlot,TransientSlot,Multicall,Context,Packing,Panic,Comparators,CAIP2, andCAIP10.
- Math: Arithmetic functions (
Understand ERC-20 Core Contracts and Interfaces
mainThe ERC-20 standard implementation includes several core components for token functionality:
IERC20: The base interface that all ERC-20 implementations must conform to.IERC20Metadata: An extended interface that includes optional metadata functions:name(),symbol(), anddecimals().ERC20: The standard implementation of theIERC20interface, which includes the optional metadata extensions (name,symbol, anddecimals).
These contracts are designed to be unopinionated, allowing developers to access internal functions (like
_mint) and expose them via custom external functions.Key features of RainbowKit
mainWallet Management
RainbowKit provides out-of-the-box management for wallet connections and disconnections. It supports numerous wallets, handles chain switching, resolves addresses to ENS, and displays wallet balances.
Customization
The UI can be adjusted to match your brand. Options include:
- Selecting predefined accent colors and border radius configurations.
- Providing a completely custom theme.
- Rendering your own custom button.
- Omitting specific features.
- Built-in dark mode support.
Industry Standards
RainbowKit is built on top of viem and wagmi, ensuring interoperability with the most common libraries in the ecosystem. It supports wallet standards such as EIP-1193 and EIP-6963 for seamless browser-based wallet connections.
Understand the ERC-1155 Multi Token Standard interfaces
mainThe ERC-1155 standard is implemented through three primary interfaces that fulfill different roles in a multi-token ecosystem:
IERC1155: The mandatory core interface for the standard.IERC1155MetadataURI: An optional extension interface for handling metadata.IERC1155Receiver: An interface used to allow contracts to receive ERC-1155 tokens.
The
ERC1155contract implements bothIERC1155and the optionalIERC1155MetadataURIby using a substitution mechanism that applies the same URI to all token types, which helps reduce gas costs.RainbowKit Key Features
mainWallet Management
RainbowKit handles connecting and disconnecting wallets, supports numerous wallet providers, manages network switching, converts addresses to ENS, and displays wallet balances.
Customization
- Branding: Match the UI to your brand using predefined accent colors and border radius configurations.
- Advanced Customization: Provide a fully custom theme, use your own custom button, or omit specific features.
- Dark Mode: Built-in support for dark mode.
Industry Standards
Choose an Access Control mechanism
mainOpenZeppelin provides several patterns for restricting function access in smart contracts depending on the complexity of your requirements:
- AccessManager: A full-fledged solution for complex systems. It supports multiple hierarchical roles and execution delays for accounts across various contracts.
- AccessManaged: A pattern where a contract delegates its access control to an external authority (which can be an
AccessManager). - AccessControl: A per-contract mechanism for managing multiple hierarchical roles and assigning them to multiple accounts within a single contract instance.
- Ownable: A simple mechanism with a single owner. Best for quick tests or very simple projects, but generally insufficient for production-grade security requirements.
- Ownable2Step: A safer version of
Ownablethat requires a two-step process to transfer ownership, preventing accidental loss of ownership.
Use ERC2981 for NFT Royalties
mainThe
ERC2981standard provides a common way to implement NFT royalties that is compatible with both ERC-721 and ERC-1155 token standards. This allows marketplaces and other applications to consistently query royalty information across different token types.Note for ERC-721 users: If you are using ERC-721, consider using
ERC721Royaltyinstead, as it includes functionality to clear royalty information from storage when a token is burned.Deploy a Remix application manually (DIY)
mainIf you are deploying a Node.js application manually, ensure you deploy the output generated by the
remix buildcommand. The required directories are:build/public/build/
Extend a built-in theme
mainInstead of redefining the entire theme, you can extend a built-in theme (like
darkThemeorlightTheme) by overriding specific tokens. This is useful for applying brand colors or specific adjustments while keeping the rest of the theme intact.- Install
lodash.mergeto combine the objects. - Import the built-in theme and the
Themetype. - Merge the built-in theme function call with your custom overrides.
- Pass the resulting object to
RainbowKitProvider.
npm install lodash.mergeimport merge from 'lodash.merge'; import { RainbowKitProvider, darkTheme, Theme, } from '@rainbow-me/rainbowkit'; const myTheme = merge(darkTheme(), { colors: { accentColor: '#07296d', }, } as Theme); const App = () => { return ( <RainbowKitProvider theme={myTheme} {...etc}> {/* Your App */} </RainbowKitProvider> ); };- Install
Deploy the RainbowKitNFT smart contract
mainDeploy the
RainbowKitNFTcontract using a Forge script. You must provide an RPC URL and a private key for the deployment account.$ forge script script/RainbowKitNFT.s.sol:RainbowKitNFTScript --rpc-url <your_rpc_url> --private-key <your_private_key>