To interact with universal applications from Solana, use the Solana Gateway. The
Solana Gateway allows you to deposit SOL (the native gas token of Solana) to an
externally-owned account (EOA) or a universal application on ZetaChain. You can
also deposit SOL and call a universal application in a single transaction using
the deposit_and_call
instruction.
Note: until full Gateway support is released on Solana, when withdrawing ZRC-20
tokens from ZetaChain to Solana, use ZRC-20 withdraw()
method directly,
instead of using ZetaChain's Gateway.
Deposit SOL
To deposit SOL to an EOA or a universal application on ZetaChain, use the
deposit
instruction of the Solana Gateway program.
pub fn deposit(ctx: Context<Deposit>, amount: u64, receiver: [u8; 20]) -> Result<()>
amount
: The amount of SOL (in lamports) to deposit.receiver
: An array of bytes containing the receiver's address
When you call the deposit
instruction, the specified amount of SOL is
transferred from your account to the Solana Gateway's Program Derived Account
(PDA).
Example of Depositing SOL to an EOA:
let receiver_address: [u8; 20] = [/* receiver's ZetaChain address */];
let amount_in_lamports: u64 = 1_000_000; // Amount in lamports (1 SOL = 1,000,000,000 lamports)
gateway::deposit(
ctx,
amount_in_lamports,
receiver_address,
)?;
To interact with the Solana Gateway from a frontend application, you can refer
to the solanaDeposit function in the ZetaChain
Toolkit (opens in a new tab).
This function demonstrates how to call the deposit
instruction from the
frontend using Anchor and the Solana Web3.js library.
Depositing SOL using the Toolkit:
npx hardhat solana-deposit --amount 0.01 --recipient 0x2DCB13e7Eb5253fD5255Ce3CbCB199B48A0C7dD9
Deposit SOL and Call Universal Apps
To deposit SOL to an EOA or a universal application on ZetaChain, use the
deposit_and_call
instruction of the Solana Gateway program.
pub fn deposit_and_call(ctx: Context<Deposit>, amount: u64, receiver: [u8; 20], message: Vec<u8>) -> Result<()>
amount
: The amount of SOL (in lamports) to deposit.receiver
: An array of bytes containing a universal contract address on ZetaChain.message
: A message passed to the universal contract.
Note: deposit_and_call
currently calls universal contract's onCrossChainCall
function and not the new onCall
function that the EVM Gateway calls. This will
be changed in the upcoming versions of the protocol after the full migration to
Gateway.
Depositing SOL and calling a universal contract using the Toolkit:
npx hardhat solana-deposit-and-call --amount 0.01 --recipient 0x0b28dd447932003D40563B0e3707ab3b80a4d956 --types '["address", "address"]' 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0 0xe7508B5026f032b37663718192bA63a40954F2c0
Recommendation on Message Formatting
We recommend formatting the message payload using ABI encoding so that it can be easily decoded in a universal application on ZetaChain. ABI encoding ensures compatibility and standardization when transmitting data across different platforms.
Example of ABI Encoding:
const ethers = require("ethers");
// Define the parameter types and values
const paramTypes = ["uint256", "string"];
const paramValues = [12345, "Hello, ZetaChain!"];
// Encode the parameters
const encodedParams = ethers.utils.defaultAbiCoder.encode(paramTypes, paramValues);
// Convert to Buffer or Uint8Array as needed
const paramsBuffer = Buffer.from(encodedParams.slice(2), "hex"); // Remove '0x' prefix
Additional Information
- Lamports and SOL: 1 SOL equals 1,000,000,000 lamports. Ensure you convert
SOL amounts to lamports when specifying the
amount
parameter. - Program Derived Account (PDA): The PDA is a special account used by the Solana Gateway program to manage deposited funds securely.
Future Support
- SPL Tokens: Support for SPL tokens (Solana's native token standard) is coming soon. This will allow you to deposit SPL tokens and interact with universal applications on ZetaChain using these tokens.
- Calling Solana Programs from Universal Applications: In the future, universal applications on ZetaChain will be able to call Solana programs directly, enabling more complex cross-chain interactions.
Error Handling
The Solana Gateway program includes several error codes to handle different failure scenarios:
SignerIsNotAuthority
: The signer is not authorized to perform the action.DepositPaused
: Deposits are currently paused.
Revert Transactions
The Solana Gateway supports transaction reversion in case of failures. If a cross-chain call fails on the ZetaChain side, the deposited SOL will be reverted back to the original sender on Solana.
Conclusion
The Solana Gateway provides a seamless way to interact with universal applications on ZetaChain from Solana. By using the Gateway instruction, you can deposit SOL and make cross-chain contract calls to universal applications on ZetaChain.