R2 Beacon Integration Guide for DApp Developers
R2 Beacon is an omni-chain identity system that tracks and scores user activities across different blockchains. By integrating R2 Beacon into your DApp, you enable "business-aware" actions that contribute to users' identity scores while maintaining privacy and security.
Note : Business-aware actions provide context about user interactions, making them more meaningful than raw transaction data. For example, instead of just recording a transfer of 0.1 ETH, you can specify that a user purchased a subscription.
An APP_ID registered with R2 Registry
Basic understanding of smart contract development
Install the R2 Beacon contract:
Copy npm install @r2-beacon/contracts
# or
yarn add @r2-beacon/contracts Import and inherit the R2BeaconEmitter contract:
Copy import { R2BeaconEmitter } from "@r2-beacon/contracts/R2BeaconEmitter.sol" ;
contract YourDApp is R2BeaconEmitter {
constructor ( bytes32 appId ) R2BeaconEmitter ( appId) {}
} Implementation Guide
Basic Integration
First, inherit from the R2BeaconEmitter contract:
Defining Business Actions
Define constants for your business actions using the _createActionId helper or direct keccak256 hashing:
Emitting Actions
Use the _emitR2Action function to record business-aware actions:
The R2BeaconEmitter interface accepts the following parameters when emitting actions:
Parameter
Type
Description
Required
Identifier for the business action
Value/amount involved in the action
Additional context data (ABI encoded)
_emitR2Action
Emits a business-aware action to the R2 Beacon system.
_createActionId
Utility function to create action identifiers from strings.
R2Action
Common Issues & Solutions
1. Invalid APP_ID
Issue : Contract deployment fails with R2Beacon_InvalidAppId
Solution : Ensure you've registered your DApp with R2 Registry and are using the correct APP_ID:
2. Action Not Registered
Issue : Actions aren't appearing in the R2 Beacon
Solution : Verify that your action identifiers are properly registered:
3. Data Encoding Issues
Issue : Action data is not properly decoded
Solution : Always use abi.encode for complex data types:
Warning : Never include sensitive user data in the data parameter. The R2 Beacon is public, and all emitted data will be visible on-chain.