Skip to main content

Polyfill Guide: spl-token

This guide will teach you how to set up the Solana spl-token library with the necessary polyfills in a React Native or Expo app.

Installation

Add the library to your project:

yarn add @solana/spl-token

Polyfills

The following polyfills are needed:

Install getRandomValues

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

yarn add react-native-get-random-values

Then, add this resolver to your project's metro.config.js

config.resolver.extraNodeModules.crypto = require.resolve(
"react-native-get-random-values"
);

This configures the Metro bundler to replace instances of require('crypto') with react-native-get-random-values, thus polyfilling getRandomValues.

tip

Alternatively, you can use the expo-crypto library to polyfill crypto.getRandomValues. View this sample app for a reference of how to polyfill the crypto class.

Example