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 was recently updated (in version 3.0.57
) to be more browser-compatible. Versions prior to this required more additional configurations via your bundling tool.
From 3.0.57
onwards, you can use the Solana OFT SDK with these minimal configurations:
- Next.js
- Vite
// next.config.ts
import type {NextConfig} from 'next';
const nextConfig: NextConfig = {
webpack: (config) => {
config.resolve.fallback = {
fs: false,
module: false,
};
return config;
},
};
export default nextConfig;
// 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.60
@layerzerolabs/lz-v2-utilities@^3.0.60
@layerzerolabs/lz-definitions@^3.0.60
@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.98.0
In package.json
add the following resolutions
/ overrides
:
- npm
- pnpm
- yarn
"overrides": {
"@solana/web3.js": "~1.98.0"
}
"pnpm": {
"overrides": {
"@solana/web3.js": "~1.98.0"
}
}
"resolutions": {
"@solana/web3.js": "~1.98.0"
}
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 you are using @solana/web3.js
v2, which is not compatible with @metaplex-foundation/umi@^0.9.2
. Ensure your package.json specifies @solana/web3.js@^1.98.0
and rerun your package manager install command.