functions

Complete reference for all frontend JavaScript functions in the veCUBE rewards UI.


connectWallet()

Connects the user's injected wallet and switches to Monad Mainnet.

Flow:

1

Detect wallet

Detects window.ethereum (MetaMask / Rabby)

2

Request accounts

Calls eth_requestAccounts to get user address

3

Switch chain

Calls wallet_switchEthereumChain → switches to Monad (0x8f)

4

Fallback chain add

Falls back to wallet_addEthereumChain if Monad not in wallet

5

Create provider + signer

Creates BrowserProvider + Signer via ethers v6

6

Verify chain

Verifies chain ID === 143

7

Update UI

Updates header UI with wallet address pill

8

Trigger load

Triggers loadNFTs() automatically

Error handling:

Code
Meaning
Action

4001

User rejected

Show toast, log warning

4902

Chain not added

Auto-add Monad network

-32603

Internal RPC error

Attempt chain add


loadNFTs()

Scans the full CubeNFT collection for tokens owned by the connected wallet.

Flow:

1

Calls balanceOf(wallet) and totalMinted() in parallel

2

Iterates token IDs 1..totalMinted in batches of 20

3

Uses Promise.allSettled — failed RPC calls don't abort the scan

4

For each token: calls ownerOf(id) → if matched, calls getCubeData(id)

5

Renders NFTs progressively as each batch resolves

6

Stops early once balance count is satisfied


renderNFTs(nfts)

Renders the scanned NFT array into the grid panel as clickable cards.

Parameter: nftsArray<{ id: number, ci: number, sym: string }>

Each card displays:

  • Colored SVG hexagon (color from colorIndex % 8)

  • Token ID formatted as #001

  • Coin symbol (e.g. PEPE)

  • "tap to select" hint

Color palette:

Index
Color

0

#39ff14 (green)

1

#ff2244 (red)

2

#ffe600 (yellow)

3

#bb99ff (purple)

4

#ff6b35 (orange)

5

#00ccff (cyan)

6

#ff88cc (pink)

7

#88ffcc (mint)


pick(id, sym)

Selects an NFT card and auto-populates the Claim form.

Parameters:

  • id — Token ID (number)

  • sym — Coin symbol string

Actions:

  • Removes .sel class from all NFT cards

  • Adds .sel to clicked card (green border + glow)

  • Sets the Token ID input field value

  • Calls calcRewards() to fetch pending amounts


calcRewards()

Fetches pending reward amounts for the selected veCube contract + token ID.

Reads: Rewards.pendingRewards(veCube, tokenId) via read-only provider

Separates CUBE and BMC amounts by matching token addresses against:

  • ADDR.cube = 0x87Bdd0E32aca3AC42d5D35baF38937Eae840f5A3

  • ADDR.bmc = 0x244DF0E3A8276aDD749AF3ec3Ff7e642B1dC46a5

Displays:

  • CUBE amount (18 decimals) + USD value at $0.001

  • BMC amount (18 decimals) + USD value at $0.05

On error: Shows 0 and (epoch active) — epoch is still running.


claimRewards()

Submits the claimAll() transaction for the selected veCube + token ID.

Pre-checks:

  • Wallet connected (calls connectWallet() if not)

  • veCube contract and token ID selected

  • currentEpoch() > 0 (Epoch 0 is not claimable yet)

Transaction:

Button states during tx:


initRead()

Initializes read-only JsonRpcProvider on page load. No wallet required.

Reads:

  • CubeNFT.totalMinted() → updates Total Minted stat

  • Rewards.currentEpoch() → updates Epoch stat and timer


tick()

Updates the epoch countdown timer every second via setInterval.

Calculates:

  • Time remaining until 2026-03-31T00:00:00Z

  • Progress percentage: (now - MAR_01) / (MAR_31 - MAR_01) × 100

Updates: Days, hours, minutes, seconds digits + progress bar + percentage label.


log(msg, cls)

Appends a timestamped line to the terminal panel.

Parameter
Values
Default

msg

Any string

cls

'ok' (green), 'er' (red), 'wn' (yellow)

'ok'

Auto-scrolls terminal to latest entry.


toast(msg)

Displays a brief notification at the bottom center of the screen. Auto-dismisses after 3.5 seconds.


cp(addr)

Copies a contract address to the clipboard and shows a confirmation toast. Used by the Contracts panel.

Was this helpful?