Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add landing page for Interoperability and Bridging under the Open Source Solutions and Integrations section #804

Open
ed-marquez opened this issue Oct 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ed-marquez
Copy link
Contributor

ed-marquez commented Oct 25, 2024

Problem

LayerZero is a new integration in the Hedera ecosystem that is available for devs. This was announced this week.

There is currently no documentation on our docs on how developers can use this integration for Hedera applications.
We need to get any documentation from LayerZero, DAs, PMs, or THF that we can link to from our docs.

Solution

Adding a landing page (similar to the Oracles one) in:
https://docs.hedera.com/hedera/open-source-solutions

Relevant links:

Alternatives

No response

@ed-marquez ed-marquez added the enhancement New feature or request label Oct 25, 2024
@mgarbs
Copy link
Contributor

mgarbs commented Oct 25, 2024

Here is some documentation that is valuable to get up and running with layerzero https://docs.layerzero.network/v2/developers/evm/oapp/overview

They use a cli tool that prompts the user to select paths for what chains the user wants its contract deployed. Once deployed you can start calling functions to send and receive messages across chains. I created this script for an example that configures the OApp to send a string from Hedera to Avalanche

import { Contract, Wallet, ethers, providers } from 'ethers'

import 'dotenv/config'
import { EndpointId } from '@layerzerolabs/lz-definitions'
import { Options } from '@layerzerolabs/lz-v2-utilities'

import MyOAppArtifact from '../artifacts/contracts/MyOApp.sol/MyOApp.json'

function tinybarToHbar(tinybarAmount: ethers.BigNumber): string {
    return ethers.utils.formatUnits(tinybarAmount, 18)
}

async function main() {
    const hederaProvider = new providers.JsonRpcProvider(
        'RPC URL GOES HERE'
    )
    const hederaPrivateKey = process.env.PRIVATE_KEY || ''
    const hederaWallet = new Wallet(hederaPrivateKey, hederaProvider)
    const hederaContractAddress = '0x768F7883954dd08B80C2157263A6D08804B3df1E' // OApp deployed address
    const hederaContract = new Contract(hederaContractAddress, MyOAppArtifact.abi, hederaWallet)

    console.log('Contract address:', hederaContractAddress)
    console.log('Wallet address:', hederaWallet.address)

    const testCases = [
        { dstEid: EndpointId.AVALANCHE_V2_TESTNET, message: 'Hello from Hedera!', payInLzToken: false },
        { dstEid: 0, message: 'Hello from Hedera!', payInLzToken: false },
        // You can add more test cases as needed
    ]

    for (const [index, testCase] of testCases.entries()) {
        console.log(`\nTest case ${index + 1}:`)
        console.log('Parameters:', testCase)

        let options = Options.newOptions()
        const GAS_LIMIT = 2000000 // Increased gas limit
        options = options.addExecutorLzReceiveOption(GAS_LIMIT, 0)
        const optionsHex = options.toHex()

        try {
            // Step 1: Call quote to get the messaging fee
            const { nativeFee, lzTokenFee } = await hederaContract.quote(
                testCase.dstEid,
                testCase.message,
                optionsHex,
                testCase.payInLzToken
            )
            console.log(`Quoted fee - Native Fee: ${nativeFee} HBAR, LZ Token Fee: ${lzTokenFee.toString()}`)

            // Since HBAR uses 8 decimals (tinybars), but ethers.js uses 18 decimals by default (wei denomination),
            // you need to scale the fee appropriately

            // Calculate the adjusted native fee
            const adjustedNativeFee = nativeFee.mul(ethers.BigNumber.from(10).pow(10)) // Adjust for decimal difference
            console.log(`Adjusted Native Fee: ${tinybarToHbar(adjustedNativeFee)} HBAR`)

            // Estimate gas
            const estimatedGas = await hederaContract.estimateGas.send(testCase.dstEid, testCase.message, optionsHex, {
                value: adjustedNativeFee,
            })
            console.log(`Estimated gas: ${tinybarToHbar(estimatedGas)}`)

            // Step 2: Send the message by calling the send function
            const tx = await hederaContract.send(testCase.dstEid, testCase.message, optionsHex, {
                value: adjustedNativeFee,
                gasLimit: estimatedGas.mul(120).div(100), // Add 20% buffer
            })
            console.log('Transaction hash:', tx.hash)

            const receipt = await tx.wait()
            console.log('Transaction confirmed in block:', receipt.blockNumber)
        } catch (error: any) {
            console.error('Error in sending message:', error.message)
            if (error.data) console.error('Error data:', error.data)
        }
    }
}

main().catch((error) => {
    console.error('Error in script:', error)
    process.exit(1)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants