Skip to content

NotEnoughNative Error Despite Increasing msg.value in Cross-Chain Transaction #143

@hupicake

Description

@hupicake

BSCSCAN LINK:https://bscscan.com/tx/0x07a23829c6193d3131f4ea4fe3442c64ccdc86fa210572da85d674353d9dc2ba

Hello LayerZero Team,

I am working on a cross-chain transfer from BSC to Solana using the LayerZero V2 protocol with the @layerzerolabs/lz-v2-utilities package. I am interacting with the OFT Adapter contract (0x7d814b9eD370Ec0a502EdC3267393bF62d891B62) on BSC to send tokens to Solana (endpoint ID: 30168). However, I keep encountering a NotEnoughNative error despite increasing the msg.value significantly.

What I Am Doing

I am using Hardhat and Ethers.js to call the send function on the OFT Adapter contract. My goal is to transfer 1 token (18 decimals) from BSC to Solana. I am dynamically querying the required fees using the quoteSend function, adjusting the nativeFee, and setting a higher msg.value to ensure sufficient funds.

Here’s the relevant code snippet:

const sendParam = {
  dstEid: 30168,
  to: "0x03d83a8646dd3101d8e7ac23a7d7b2a5a4e52b371504472fe826d71ada306207",
  amountLD: BigInt("1000000000000000000"), // 1 token
  minAmountLD: BigInt("995000000000000000"), // 0.995 token (0.5% slippage)
  extraOptions: "0x",
  composeMsg: "0x",
  oftCmd: "0x"
};

const { nativeFee, lzTokenFee } = await quoteFees(contract, sendParam);
const adjustedNativeFee = nativeFee * BigInt(2); // Double the queried fee as a buffer
const totalValue = adjustedNativeFee * BigInt(4); // Set msg.value to 4x the adjusted fee

const sendParamTuple = [
  sendParam.dstEid,
  sendParam.to,
  sendParam.amountLD,
  sendParam.minAmountLD,
  sendParam.extraOptions,
  sendParam.composeMsg,
  sendParam.oftCmd
];
const feeTuple = [adjustedNativeFee, lzTokenFee];

const tx = await contract.send(
  sendParamTuple,
  feeTuple,
  "0xc34b76ae97Dd90e1304e20B5473Cb9a80F1166A4", // _refundAddress
  { value: totalValue, gasLimit: 600000 }
);

The quoteFees function queries the fees using quoteSend:

async function quoteFees(contract, sendParam) {
  const sendParamTuple = [
    sendParam.dstEid,
    sendParam.to,
    sendParam.amountLD,
    sendParam.minAmountLD,
    sendParam.extraOptions,
    sendParam.composeMsg,
    sendParam.oftCmd
  ];
  const [nativeFee, lzTokenFee] = await contract.quoteSend(sendParamTuple, false);
  const adjustedNativeFee = nativeFee * BigInt(2);
  console.log("Queried Fees:", {
    nativeFee: ethers.formatEther(nativeFee),
    adjustedNativeFee: ethers.formatEther(adjustedNativeFee),
    lzTokenFee: ethers.formatEther(lzTokenFee)
  });
  return { nativeFee: adjustedNativeFee, lzTokenFee };
}

Parameters Used

For my latest transaction:

  • Queried nativeFee: 738287943339606 Wei (~0.000738 BNB)
  • Adjusted nativeFee: 738287943339606 * 2 = 1476575886679212 Wei (~0.001476 BNB)
  • Total msg.value: 1476575886679212 * 4 = 5906303546716848 Wei (~0.005906 BNB)
  • Transaction Hash: 0x07a2382c6193d131f4ea4fe3442c64ccd86fa210572da85d674353d9dc2ba

Error Encountered

The transaction failed with the following error:

Fail with Custom Error 'NotEnoughNative (msgValue=2953151773358424)'

This error persists even after increasing the msg.value. In my latest attempt, I set msg.value to 0.005906 BNB, but a previous attempt with msgValue=0.002953 BNB also failed with the same error.

Comparison with a Successful Transaction

I found a successful transaction on BSCScan that uses the same OFT Adapter contract and triggers Transfer events, indicating a successful cross-chain transfer:

  • Successful Transaction: [Link to successful transaction on BSCScan]
  • Details:
    • From: 0x8520Feed7CdC4905b7B5C3986b19642A456ce983
    • To: 0x7d814b9eD370Ec0a502EdC3267393bF62d891B62 (Bubblemaps: BMT Token)
    • Transfer: 0.001804560590972425 BNB to LayerZero: EndpointV2, followed by additional transfers.
  • Parameters:
    • Queried nativeFee: 1804560590972425 Wei (~0.001804 BNB)
    • msg.value: At least 0.00180456 BNB (exact value not specified but inferred from transfers)

My parameters are very similar, and my msg.value is significantly higher than the successful transaction's nativeFee, yet my transaction fails.

Questions

  1. Why am I still getting the NotEnoughNative error even with a msg.value of 0.005906 BNB, which is much higher than the successful transaction's nativeFee of 0.001804 BNB?
  2. Is there a way to accurately calculate the required msg.value for cross-chain transfers to Solana? Does quoteSend account for all fees, including execution costs on the destination chain?
  3. Are there any additional requirements (e.g., token approvals, specific extraOptions) that I might be missing for a successful cross-chain transfer?

Any help would be greatly appreciated! Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions