Skip to main content

Polyfill Guide: Anchor

This guide will teach you how to set up the Anchor Javascript SDK with the necessary polyfills in a React Native or Expo app.

Installation

Add the Anchor library to your project:

yarn add @coral-xyz/anchor

Polyfills

The following polyfills are needed:

Install buffer

:::

yarn add buffer

Install getRandomValues

Add the react-native-get-random-values library to your project.

yarn add react-native-get-random-values

Then, import the library in your app's entrypoint file (e.g index.js), before the Anchor library is imported.

import "react-native-get-random-values";
// ...other imports below

Install assert

Add the assert library to your project.

yarn add assert

Install text-encoding

Add the text-encoding library to your project.

yarn add text-encoding

Then, populate the global.TextEcoder value in your app's entrypoint file (e.g index.js).

// ...imports
global.TextEncoder = require("text-encoding").TextEncoder;

Example