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 mint new OFT Config Accounts, so that you own their OFT's Upgrade Authority.

Requirements

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

  • Solana CLI: 1.17.31
  • Anchor: 0.29.0

You can find the sample codebase in the LayerZero Solana OFT Example Repo.

Cloning Example Solana Program

git clone git@github.com:LayerZero-Labs/example-oft.git

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

Build & Test

Install dependencies, build the program, and run tests to ensure everything is set up correctly:

yarn && yarn build && yarn test

Verify

Navigate to the contract directory to start the verification process. This ensures that the program binaries are correct and verifiable:

cd packages/solana/contracts

With Anchor

Use Anchor to build and verify the program:

anchor build --verifiable

With Solana-Verify

Alternatively, you can use Solana-Verify to build and verify the program:

solana-verify build

Deploy

Navigate to the contract directory to prepare for deployment:

cd packages/solana/contracts

With Anchor

Deploy the program using Anchor. This uploads the program binary to the Solana blockchain and assigns it the specified program ID:

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

After deployment, you can check that your program deployed successfully by running:

$ solana program show --programs --url RPC_URL --keypair deployer-keypair.json

Program Id | Slot | Authority | Balance
CKsfN2UvdF6BxWmt12576GN4EtLynA7MxSqEm6jrCqMh | 279715124 | 6tzUZqC33igPgP7YyDnUxQg6eupMmZGRGKdVAksgRzvk | 8.24730072 SOL

With Solana-Verify

Deploy the program using Solana-Verify. This also uploads the program binary to the Solana blockchain:

solana program deploy --program-id target/deploy/oft-keypair.json target/deploy/oft.so -u mainnet-beta

For more details, please visit Solana Verify CLI and 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.

Minting OFT Config Accounts

After successful program deployment, you can now use the program to create either a Solana OFT Native 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