R5 Network
WebsiteR5 LabsGitHub
  • Getting Started
    • Hello & Welcome!
  • About R5
    • Overview
    • R5 Components
    • Consensus Mechanism
    • zkNet (Privacy)
  • R5 Coin
  • R5 Tokenomics
  • Tutorials & Guides
    • Connect & Use R5
      • R5 Desktop Wallet
      • MetaMask
      • Rabby Wallet
      • Coinbase Wallet
    • zkNet Web Wallet
    • R5 Desktop Wallet
      • Interface Overview
      • Send a Transaction
      • Receive a Transaction
      • Backup Your Wallet
      • Retrieve Your Private Key
    • How To: Deploy a Node
    • How To: Mine R5
    • How To: GPU Mine R5
    • How To: Build R5 From Source
    • How To: Connect Nodes Over LAN
  • For Developers
    • R5 SDK
      • R5 Relayer
      • R5 Console
      • JS Console
      • CLI Wallet
      • SCdev
      • SSL Proxy
    • Hardware Requirements
    • R5 Testnet
    • R5 Devnet
    • Local Networks
    • RPC API
      • admin
      • debug
      • ethash
      • miner
      • net
      • r5 (eth)
      • rpc
      • txpool
      • web3
    • R5 Analytics API
    • zkNet API
    • Node Configuration
    • Ethash-R5
    • Smart Contracts
    • Wrapped R5 (Native)
    • Tokens & NFTs
  • Bug Bounty Program
  • Resources
    • Website
    • R5 Labs
    • R5 Core Repository
Powered by GitBook
On this page
  • Overview
  • Motivation
  • Contract Architecture
  • Key Functions
  • Events
  • Security Considerations
  • Gas Efficiency
  • Integration Examples
  • ABI Reference
  1. For Developers

Wrapped R5 (Native)

This page describes the Wrapped R5 (WR5) token contract, its rationale, interface, and integration guidelines for developers building on the R5 network.

Canonical WR5 address on R5 Mainnet, Testnet, and Devnet:

0x8cDAb49A98e190A14B1b1795A4f0E9cDa80445b4

Overview

Wrapped R5 (WR5) is an ERC-20–compatible token that represents native R5 coins in a smart-contract form. It enables R5 to participate in DeFi protocols, DEXs, and other smart-contract–based systems.

  • Token Name: Wrapped R5

  • Symbol: WR5

  • Decimals: 18

  • Contract Standards: Minimal ERC-20 + wrap/unwrap functions

  • Solidity Version: 0.8.29

Motivation

Native R5 transfers are handled by the consensus layer and cannot directly interact with EVM-based contracts. WR5 bridges this gap by:

  1. Wrapping: Locking native R5 in the WR5 contract in exchange for an equal amount of WR5.

  2. Unwrapping: Burning WR5 to redeem locked R5.

This allows seamless integration with ERC-20 tooling (DEXs, lending platforms, wallets).

Contract Architecture

The contract maintains two primary mappings:

mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
  • balanceOf[account]: WR5 token balance of account.

  • allowance[owner][spender]: Remaining WR5 spender may transfer on behalf of owner.

Native R5 held by the contract (address(this).balance) equals total WR5 supply.

Key Functions

Function

Signature

Description

deposit

function deposit() external payable

Wrap native R5: mints WR5 = msg.value, credited to msg.sender.

withdraw

function withdraw(uint256 amount) external

Unwrap WR5: burns amount WR5, sends amount native R5 to caller.

totalSupply

function totalSupply() external view returns(uint256)

Returns total WR5 (contract’s R5 balance).

approve

function approve(address spender, uint256 amount) external returns(bool)

Set allowance for spender.

transfer

function transfer(address to, uint256 amount) external returns(bool)

Transfer WR5 from caller to to.

transferFrom

function transferFrom(address from, address to, uint256 amount) external returns(bool)

Transfer WR5 on behalf (uses allowance).

Wrapping & Unwrapping

// Wrap 1.0 R5 into 1e18 WR5:
wrappedToken.deposit{value: 1 ether}();

// Unwrap 0.5 WR5 back to R5:
wrappedToken.withdraw(0.5 ether);
  • receive() and fallback() invoke deposit(), allowing simple sendTransaction({ to: WR5, value }).

Events

Event

Signature

Emitted When

Deposit

event Deposit(address indexed to, uint256 amount)

User wraps native R5

Withdrawal

event Withdrawal(address indexed from, uint256 amount)

User unwraps WR5

Transfer

event Transfer(address indexed from, address indexed to, uint256 value)

Standard ERC-20 transfer

Approval

event Approval(address indexed owner, address indexed spender, uint256 value)

Standard ERC-20 approval

Security Considerations

  • Reentrancy: Withdrawal uses transfer, which caps gas and reverts on failure—mitigating reentrancy.

  • Overflow/Underflow: Solidity 0.8’s built‑in checks prevent arithmetic errors.

  • Infinite Allowance: type(uint256).max sentinel avoids unnecessary storage writes when users want unlimited allowance.

  • Ownership: No admin or upgradeable logic; the contract is immutable once deployed.

Gas Efficiency

  • Minimal storage writes (no mint/burn hooks beyond mapping updates).

  • Single‐contract, minimal-function interface reduces deployment footprint.

  • Avoids external library calls (SafeMath, OZ code) thanks to built‑in checks.

Integration Examples

Web3.js

const WR5 = new web3.eth.Contract(abi, address);
// Wrap 1 R5
deployer.sendTransaction({ to: address, value: web3.utils.toWei('1', 'ether') });

// Check WR5 balance
const bal = await WR5.methods.balanceOf(user).call();

Ethers.js

const wr5 = new ethers.Contract(addr, abi, signer);
await wr5.deposit({ value: ethers.utils.parseEther('2') });
const supply = await wr5.totalSupply();

ABI Reference

A minimal ABI for WR5 interactions:

[
  {"inputs":[],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},
  {"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},
  {"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},
  {"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},
  {"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},
  {"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}
]

PreviousSmart ContractsNextTokens & NFTs

Last updated 19 days ago