Using the Solana OFT SDK in the Frontend
The Solana OFT SDK has been updated to be browser-compatible. Versions prior to3.0.71 required more additional configurations via your bundling tool.
- Next
- Vite
For Next projects, no additional configurations are required to use the Solana OFT SDK.
Requirements
@layerzerolabs/oft-v2-solana-sdk@^3.0.86@layerzerolabs/lz-v2-utilities@^3.0.86@layerzerolabs/lz-definitions@^3.0.86@metaplex-foundation/umi@^0.9.2@metaplex-foundation/umi-bundle-defaults@^0.9.2@metaplex-foundation/umi-signer-wallet-adapters@^0.9.2@solana/web3.js@^1.95.8
Applying overrides for @solana/web3.js
In package.json add the following resolutions / overrides to ensure a consistent version of @solana/web3.js is used:
Compatibility with @solana/web3.js
Under the hood, uses @metaplex-foundation/umi, which is an alternative to @solana/web3.js.
If your project is using @solana/web3.js, you can utilize adapters for @solana/web3.js.
Troubleshooting
Invalid Connection
This can occur when there are multiple incompatible versions of @solana/web3.js. We need to ensure a consistent version is used due to the usage of @metaplex-foundation/umi@^0.9.2.
To verify that this is the issue, run npm ls @solana/web3.js and check whether there are multiple versions of @solana/web3.js in the output.
To solve this issue, do the following:
- delete your
node_modulesfolder - delete your package manager’s lockfile
- in your package.json, specify
@solana/web3.js@^1.95.8as the dependency and also apply overrides - rerun your package manager install command.