react-native-polyfills

A set of React Native setup rules for MetaMask Connect. React Native is a framework for building mobile apps with JavaScript, and polyfills provide browser-like functions that mobile apps may lack.

In plain words
What is it for?
Adding the required window, Event, CustomEvent, Buffer, and random-value support for MetaMask Connect apps, including wagmi integrations.
Why use it?
It helps avoid runtime errors caused by missing browser or cryptography features and by importing setup files in the wrong order.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/metamask/metamask-connect-cursor-plugin/react-native-polyfills
Clone the repo
git clone --depth 1 https://github.com/MetaMask/metamask-connect-cursor-plugin
Per session 1,177 This file is loaded in full into every session.
When invoked 1,177 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01177 $0.01177
Opus 5 $0.00589 $0.00589
Sonnet 5 $0.00235 $0.00235
Haiku 4.5 $0.00118 $0.00118

Measured yesterday against content hash ab2e2027ea38, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

react-native-polyfills scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/react-native-polyfills.mdc · 106 lines

How it starts

The opening of the file, as written. The whole thing — 106 lines — stays where its author put it; the contents beside it link to each section on GitHub.

React Native Polyfills for MetaMask Connect

Per-Package Polyfill Requirements

Different integrations need different polyfills. Do not blindly copy the full set:

Polyfill connect-evm / connect-solana (standalone) + wagmi
react-native-get-random-values RN < 0.72 only (see below) RN < 0.72 only
Buffer Safety net only (self-polyfilled by connect-multichain) Safety net only
window object Required for correct deeplink/platform detection Required
Event Not required Required (wagmi uses DOM events)
CustomEvent Not required Required (wagmi uses DOM events)

Import Order (Critical)

// Entry file (_layout.tsx / index.js) — order is critical
import 'react-native-get-random-values'; // MUST be first (if used)
import './polyfills';                     // window shim, and Event/CustomEvent if using wagmi

Incorrect order causes crypto.getRandomValues is not a function at runtime.

react-native-get-random-values

  • Required only for React Native < 0.72 — Hermes 0.72+ exposes globalThis.crypto.getRandomValues natively
  • Still recommended as an explicit safety net — especially if any dependency has its own minimum RN version assumptions
  • Must be the very first import in the entry file, before anything that touches crypto

Buffer Polyfill

  • @metamask/connect-multichain self-polyfills Buffer via its React Native entry point — not needed for the SDK itself
  • Still recommended to set global.Buffer = Buffer in polyfills.ts as a safety net for peer deps (e.g. eciesjs, @solana/web3.js) that may load before connect-multichain
  • Install: npm install buffer

window Object Polyfill

  • Required for correct platform and deeplink behaviour — getPlatformType() in connect-multichain inspects window and global.navigator.product to decide between the deeplink path and the install-modal path
  • All window.* accesses inside the SDK are guarded, so code will not crash without it, but isSecure() returns the wrong value and deeplinks will not trigger
  • Provide at minimum: location, addEventListener, removeEventListener, dispatchEvent

Read the full file on GitHub · 106 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 106 lines · 1,177 tokens per session scan A ab2e2027ea38

Subscribe to this mod's changes

react-native-polyfills is a cursor rule published in the GitHub repository MetaMask/metamask-connect-cursor-plugin (2 stars, last pushed 2mo ago), licensed MIT. It adds 1,177 tokens to every session, about $0.0059 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.