LayerZero V2 Solana OFT SDK
You can use the Solana OFT SDK - @layerzerolabs/oft-v2-solana-sdk library to interact with your Solana OFT.
Setting up a project using the LayerZero CLI would have given you scripts under the tasks/solana folder that utilizes the Solana OFT SDK. You can refer to tasks/solana/sendOFT.ts for the example usage.
Using the Solana OFT SDK in the Frontend
The Solana OFT SDK has been updated to be browser-compatible. Versions prior to 3.0.71
required more additional configurations via your bundling tool.
- Next
- Vite
For Vite projects, the following are the minimal configurations required to work. nodePolyfills
is required as Buffer
is required by @solana/web3.js
but Vite does not polyfill it by default.
// vite.config.ts
import {defineConfig} from 'vite';
import react from '@vitejs/plugin-react';
import {nodePolyfills} from 'vite-plugin-node-polyfills';
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), nodePolyfills()],
});
Requirements
@layerzerolabs/oft-v2-solana-sdk@^3.0.71
@layerzerolabs/lz-v2-utilities@^3.0.71
@layerzerolabs/lz-definitions@^3.0.71
@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:
- npm
- pnpm
- yarn
"overrides": {
"@solana/web3.js": "~1.95.8"
}
"pnpm": {
"overrides": {
"@solana/web3.js": "~1.95.8"
}
}
"resolutions": {
"@solana/web3.js": "~1.95.8"
}
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_modules
folder - delete your package manager's lockfile
- in your package.json, specify
@solana/web3.js@^1.95.8
as the dependency and also apply overrides - rerun your package manager install command.