Skip to main content
Version: Endpoint V2 Docs

LayerZero V2 Solana OFT Program

caution

The Solana OFT, Endpoint, and ULN Programs are currently in Mainnet Beta!


The Omnichain Fungible Token (OFT) Standard allows fungible tokens to be transferred across multiple blockchains without asset wrapping or middlechains.

This standard works by either debiting (burn / lock) tokens on the source chain whenever an omnichain transfer is initiated, sending a message via the protocol, and delivering a function call to the destination contract to credit (mint / unlock) the same number of tokens debited. This creates a unified supply across all networks LayerZero supports that the OFT is deployed on.

OFT Standard

OFT Example OFT Example

OFT Adapter Standard

OFT Adapter OFT Adapter

While the typical path for Solana program development involves interacting with or deploying executable code that defines your specific implementation, and then minting accounts that want to use that interface (e.g., the SPL Token Program), the OFT Program is different in this respect.

Because every Solana Program has an Upgrade Authority, and this authority can change or modify the implementation of all child accounts, developers wishing to create cross-chain tokens on Solana should deploy their own instance of the OFT Program to create new OFT Store accounts, so that you own their OFT's Upgrade Authority.

note

End-to-end instruction on how to deploy a Solana OFT can be found in the README at https://github.com/LayerZero-Labs/devtools/tree/main/examples/oft-solana, which will be the README of your project when you setup using the LayerZero CLI.

Requirements

To ensure compatibility and smooth operation, please use the following versions:

  • Rust: v1.75.0
  • Solana CLI: 1.17.31
  • Anchor: 0.29.0
  • Docker

You can find the sample codebase in the LayerZero Developer Tools Repo.

Get the code

Setup your project using the LayerZero CLI.

LZ_ENABLE_SOLANA_OFT_EXAMPLE=1 npx create-lz-oapp@latest

Generate Program Keypairs

Create program keypair files if they do not exist:

cd packages/solana/contracts

solana-keygen new -o target/deploy/endpoint-keypair.json
solana-keygen new -o target/deploy/oft-keypair.json

anchor keys sync

Install Dependencies

pnpm install

Test

Run tests to ensure everything is set up correctly:

pnpm test

Build

anchor build -p oft --verifiable

Deploy

Navigate to the contract directory to prepare for deployment:

solana program deploy --program-id target/deploy/oft-keypair.json target/verifiable/oft.so -u devnet

To learn more about deploying Solana programs, refer to Deploy a Solana Program with the CLI.

info

If you encounter issues during compilation and testing, it might be due to the versions of Solana and Anchor. You can switch to Solana version 1.17.31 and Anchor version 0.29.0, as these are the versions we have tested and verified to be working.

(Optional) Verify the OFT Program

To proceed with this section, you must install solana-verify

Verify locally

View the program hash of the locally built OFT program:

solana-verify get-executable-hash ../../target/verifiable/oft.so

Compare with the on-chain program hash:

solana-verify get-program-hash -u devnet <PROGRAM_ID>

Submit to the OtterSec API

This will provide your program with the Verified status on explorers.

First, you would need to upload your project into a public repo. Note that you must upload your entire project's folder rather than only the OFT program's folder. Doign the latter would result in a different hash being generated by OtterSec's build task.

Verify against the code in the git repo:

solana-verify verify-from-repo -u devnet --program-id <PROGRAM_ID> <GIT_REPO_URL> --library-name oft

(mainnet only) Verify against the code in the git repo and submit for verification status:

solana-verify verify-from-repo --remote -u mainnet-beta --program-id <PROGRAM_ID> <GIT_REPO_URL> --library-name oft
note

Learn more about the solana-verify CLI from the official repo>).

Creating OFT Store accounts

After successful program deployment, you can now use the program to create either a vanilla Solana OFT Account or Solana OFT Adapter Account.

Troubleshooting

Retrying Failed Transactions

If a transaction fails, it may be due to network congestion or other temporary issues. You can retry the transaction by resubmitting it. Ensure that you have enough SOL in your account to cover the transaction fees.

Recovering Failed Rent

solana program close --buffers --keypair deployer-keypair.json -u mainnet-beta
note

For more troubleshooting help, refer to the Solana OFT README.