A Developer’s Intro to Wormhole and Product Ideas
Technical Deep Dive into the best open-source blockchain development platform.
1. Challenge Overview
As blockchain technology rapidly evolves, one of the foremost challenges that developers encounter is the lack of interoperability between different blockchain networks.
Each blockchain operates within its own ecosystem, often isolated from others, which creates barriers to the seamless transfer of assets and data across networks.
This approach hampers the development of decentralized applications (dApps) and limits the potential for collaboration and innovation in the blockchain space.
Wormhole solves this issue, in this deep dive you as a developer will learn all about wormhole, its functionality, offerings and SDK and more
2. Genesis
Wormhole have emerged as a tool provider cued to bridge the gap between disparate blockchain ecosystems and enable interoperability as it aims to unlock new possibilities for developers and users by enabling the frictionless exchange of assets and data across supported blockchains.
Wormhole V1 was introduced in 2020 by Certus One and was initially conceived as a traditional token bridge between Ethereum and Solana. It served as the first bridge on Solana and was responsible for bootstrapping a large amount of the liquidity in the early Solana and Serum ecosystems.
Wormhole v2 launched in August 2021 as a decentralized generic interoperability protocol for multiple blockchain ecosystems with initial support for Solana, Terra, Ethereum and Binance Smart Chain.
As of now 2024, Hundreds of companies and applications use Wormhole’s blockchain connectivity platform to securely and scalably grow their user base, increase market share, and drive more on-chain activity. Making it indeed The Web of Web3.
At Osmoscon 2023, the Wormhole Foundation announced the launch of the Wormhole Gateway, opening up exciting possibilities for cross-chain interactions.
The Wormhole Gateway, an application-specific blockchain powered by the Cosmos SDK. Serves as an onramp to the interchain, connecting liquidity and users from 23+ blockchains to the entire interchain using the IBC (Inter-Blockchain Communication) protocol.
3. Wormhole: Introduction to Wormhole
3.1 What is wormhole?
Wormhole acts as a conduit for the seamless transfer of assets and data, allowing users to leverage the strengths of multiple blockchains while transcending the limitations of individual ecosystems. By enabling cross-chain communication and interoperability, Wormhole empowers developers to create innovative solutions and users to access a broader range of decentralized services.
Wormhole as a cross-chain communication platforms break down the barriers of networks operating in isolation and aims to foster a more interconnected and versatile blockchain landscape.
They enable developers to create more robust, efficient, and scalable applications by leveraging the combined strengths of multiple chains, thus paving the way for widespread blockchain adoption and innovative use cases.
3.2 Why is wormhole important?
Basically, Wormhole is a generic message passing protocol that enables communication between blockchains.
The significance of Wormhole lies in its ability to overcome the inherent limitations of siloed blockchain ecosystems. By providing a decentralized and trustless mechanism for asset transfers and communication, Wormhole fosters collaboration and innovation across disparate networks.
This interoperability opens up new avenues for decentralized finance (DeFi), non-fungible tokens (NFTs), gaming, and other use cases, driving the evolution of the blockchain space as a whole.
As a developer or even a user I strongly advise you to watch this video below from wormhole, on an intro to blockchain interoperability, it will give you a deeper understanding on the interoperability motion and why it’s necessary. ⬇
3.3 Wormhole unique features
Wormhole boasts several unique features that distinguish it as a leading cross-chain bridge protocol:
Cross-Chain Asset Transfers:
Wormhole facilitates the seamless transfer of digital assets, such as tokens, between different blockchain networks, enabling users to access liquidity and assets across ecosystems.Decentralized Governance:
Wormhole operates under a decentralized governance model, allowing the community of token holders to govern the protocol's development, upgrades, and parameters, ensuring transparency and adaptability.Smart Contract Support:
Wormhole supports the creation and execution of smart contracts on compatible blockchains, enabling developers to build complex decentralized applications that leverage cross-chain functionality.Interoperable Data Transfer:
Wormhole enables the transfer of data between different blockchains, allowing for cross-chain communication and interoperability, which is essential for various use cases such as decentralized finance, gaming, and supply chain management.Queries:
Developers can pull any on-chain data to their applications on any chain, on-demand.Connect:
Integrating an in-app bridging widget with just 3 lines of code allows liquidity and user growth for Cosmos-based apps and chains.Ecosystem Support:
Wormhole powers apps across Web3, including DeFi protocols, NFT collections, and natively cross-chain applications. It has been unconditionally approved by Uniswap’s Bridge Assessment Committee for cross-chain deployments1.Security:
Wormhole prioritizes security with validator nodes, continuous audits, and a $2.5 million bug bounty program. It is fully open source and contributes to industry-wide security.Ecosystem Programs:
Backed by industry supporters, Wormhole offers funds and grants to visionary teams building the next generation of Web3 applications.
These features collectively make Wormhole an invaluable tool for developers looking to explore the new frontier of cross-chain applications, offering a blend of security, versatility, and user-centric design.
4. Wormhole Architecture
Initially, comprehending the essence of Wormhole proved challenging. I found myself questioning the necessity of such a tool. After all, wasn't it straightforward to communicate between blockchains like Solana and Ethereum?
However, a scenario posed by a friend transformed my perspective. They asked, "What if a hacker infiltrated your relayer system and manipulated the messages between Solana and Ethereum? How would you mitigate this risk?" It was then that I truly grasped the value of Wormhole.
Wormhole acts as a safeguard, verifying that messages originate from my Solana program and not from an unauthorized source. The architecture is built to be resilient and decentralized, ensuring no single point of failure.
This setup allows Wormhole to maintain a trustless environment, crucial for operations in the blockchain space. So, what noteworthy components does Wormhole comprises of?
4.1 On-Chain Components
Emitter
A contract responsible for invoking the publish message method on the Core Contract. When triggered, the core contract records an event in the Transaction Logs, containing details about the emitter and a sequence number to identify the message. This emitter can either be your xDapp or an existing ecosystem protocol.
Some examples of existing contracts that function as Emitters include:
- xAsset Contracts- These contracts facilitate the conversion of normal tokens into xAssets and enable their bridging across chains.
-Relay Contracts- These contracts enable cross-chain applications to transmit messages to a specific blockchain via the decentralized Generic Relayer network.
- Worm Router Contracts- These contracts empower developers to transform their Dapps into cross-chain applications that users on any Wormhole supported chain can interact with solely through client-side code.
Wormhole Core Contract-
This is the primary contract observed by the Guardians, essential for facilitating cross-chain communication.Transaction Logs-
Blockchain-specific logs utilized by the Guardians to monitor messages emitted by the core contract.
4.2 Off-Chain Components
Guardian Network -
Validators comprising a dedicated P2P network. Guardians are tasked with observing and validating messages emitted by the Core Contract on each supported chain, generating VAAs (signed messages) as a result.Guardian -
An individual validator among the 19 validators constituting the Guardian Network, contributing to the VAA multisig process.Spy -
A daemon within the Guardian Network that subscribes to published messages, capable of observing and forwarding network traffic to aid in scaling up VAA distribution.API -
A REST server utilized to retrieve details regarding a VAA or the Guardian Network.VAAs -
Verifiable Action Approvals (VAAs) represent the signed attestation of an observed message from the wormhole core contract.Relayer -
Any off-chain process responsible for relaying a VAA to the target chain.Standard Relayers -
Decentralized relayer network delivering messages requested on-chain via the Wormhole Relay Contract, also known as Generic Relayers.Specialized Relayers -
Relayers designed to handle VAAs for specific protocols or cross-chain applications exclusively. They can execute custom off-chain logic, potentially reducing gas costs and enhancing cross-chain compatibility. Currently, developers of cross-chain applications are tasked with developing and hosting specialized relayers.
The image above shows a structure of how the components unfold.
While the definitions may seem intricate, let's dive deeper to enhance our understanding in the following section on how wormhole works.
5. How it Works
This section of the article is based on the following image, which outlines the process in three stages ⬇.
Source chain
Off chain
Destination chain
Source Chain
In the source chain, two key smart contracts are involved: the Wormhole smart contract and your custom smart contract. Interaction with the system primarily occurs through your own smart contract, which issues a "Call" to the Wormhole smart contract. Upon receiving this call, the Wormhole smart contract executes the necessary processing and emits a unique communication known as the 'Wormhole Message.'
Off Chain
Once the Wormhole Message is created, it undergoes immediate scrutiny by the Guardians of the Wormhole Network for validation. If deemed valid, the Guardians endorse the message. When 13 out of 19 Guardians agree, indicated by their responses, the message transitions into a signed VAA (Verifiable Action Approval). The relayer retrieves the signed VAA and initiates a call to your smart contract (Integrator Contract) located on the destination chain.
Destination Chain
The Integrator contract processes the signed VAA and forwards it to the Wormhole Contract on the destination chain, which validates the VAA. If the VAA is deemed invalid, no action is taken. If valid, the VAA is decoded, and the embedded message is interpreted. Subsequent actions are based on the contained instructions or displayed as necessary.
6. Wormhole SDK
The Wormhole SDK (Software Development Kit) serves as a comprehensive suite of tools, libraries, and documentation meticulously crafted by Wormhole. Its primary aim is to simplify the process of building applications that harness the capabilities of the Wormhole protocol. By providing developers with essential resources, the SDK facilitates seamless integration of Wormhole functionalities into their projects, ensuring efficiency and effectiveness.
6.1 Key Advantages of the Wormhole SDK
Simplified Integration: The SDK is engineered for easy integration into blockchain development endeavors, offering robust support for a variety of programming languages. This ensures that developers can seamlessly incorporate Wormhole's capabilities into their projects without encountering unnecessary complexities.
Extensive Documentation: With its comprehensive documentation, the SDK provides developers with a wealth of information, including usage examples and step-by-step guides. This extensive documentation equips developers with the necessary insights to swiftly grasp and leverage the various features and functionalities of the SDK.
Vibrant Community Support: Developers benefit from access to a thriving and engaged community where they can collaborate, share knowledge, and seek assistance when encountering challenges during the development process. This vibrant community fosters an environment of collaboration and collective growth, enhancing the overall development experience.
With the Wormhole SDK, developers tend embark on their blockchain development journey with confidence, using the tools, resources, and community support needed to bring their innovative ideas to life effectively.
6.2 Installing the Wormhole SDK
Let’s quickly run through on how to install the wormhole SDK
Step 1: Prepare Your Development Environment Ensure that Node.js and npm are installed on your system before you commence. Additionally, have a reliable code editor ready for scripting, such as Visual Studio Code.
Step 2: Install the Wormhole SDK Navigate to your project directory using your terminal or command prompt. Then, execute the following npm command to install the Wormhole SDK:
npm install @certusone/wormhole-sdk
Step 3: Import Essential Modules In your JavaScript file designated for Wormhole operations, import the Wormhole SDK module using the require function:
const Wormhole = require('@certusone/wormhole-sdk');
Step 4: Initialize Wormhole Instantiate a new Wormhole SDK instance and configure it with your desired network settings. Specify whether you are working on the testnet or mainnet, and provide the RPC URL accordingly:
const wormhole = new Wormhole({ network: 'testnet', // or 'mainnet' rpcURL: 'https://api.testnet.wormholescan.io', });
Replace 'testnet' with 'mainnet' if you intend to deploy your application on the main network.
With your development environment set up and the Wormhole SDK initialized, you are ready to begin constructing your application. Here are some common tasks you may undertake:
Sending Messages:
Utilize Wormhole to dispatch messages or directives across disparate blockchains.
Learn the detailed process to sending your first cross chain message here - https://docs.wormhole.com/wormhole/quick-start/cross-chain-dev
Receiving Messages:
Implement functionality to capture and process messages originating from other blockchains.
Smart Contract Integration:
If your application interfaces with smart contracts, integrate Wormhole functionalities to enable seamless cross-chain communication.
Step 5: Develop Token Transfer Functionality Let's create a function to enable token transfers via Wormhole. This function will require parameters such as the sender's address, recipient's address, and the token amount:
async function transferTokens(senderAddress, recipientAddress, amount) {
try {
// Specify the token contract address
const tokenAddress = 'YOUR_TOKEN_ADDRESS';
// Provide the private key of the sender's wallet
const senderPrivateKey = 'SENDER_PRIVATE_KEY';
// Initiate the token transfer using Wormhole
const result = await wormhole.transfer({
tokenAddress,
senderPrivateKey,
recipientAddress,
amount,
});
console.log('Token transfer successful:', result);
} catch (error) {
console.error('Error transferring tokens:', error);
}
}
Replace 'YOUR_TOKEN_ADDRESS' with the actual token contract address and 'SENDER_PRIVATE_KEY' with the sender's private key.
Step 6: Execute the Transfer Function Now, you can call the transfer tokens function with the necessary parameters to start the token transfer:
const senderAddress = 'SENDER_WALLET_ADDRESS';
const recipientAddress = 'RECIPIENT_WALLET_ADDRESS';
const amount = 100; // Specify the amount of tokens to transfer
transferTokens(senderAddress, recipientAddress, amount);
Substitute 'SENDER_WALLET_ADDRESS' and 'RECIPIENT_WALLET_ADDRESS' with the corresponding wallet addresses.
Well done! You've successfully implemented token transfer functionality using Wormhole. Further code and setting up examples will be discussed later in this deep dive.
Here is a video I recommend to developers who want to start building cross-chains with wormhole. ⬇
7. How the core bridge works layman explanation
The Wormhole SDK includes the Core Wormhole Bridge, which operates by deploying smart contracts on both the Source Chain (where the data currently resides) and the Target Chain (where the data will be moved). The workflow generally follows these steps:
1. An end user or another smart contract publishes a message using the Bridge Contract on the Source Chain.
2. The Wormhole Network observes this transaction and issues a SignedVAA once it crosses its confirmation threshold.
3. An off-chain process collects the SignedVAA and submits it in a transaction to the Bridge Contract on the Target Chain, which can parse and verify the message.
Wormhole Token Bridge
The Wormhole Token Bridge, although not strictly part of the Wormhole protocol, is built and packaged as part of the Wormhole SDK due to the importance of token transfers. It works similarly to the Core Bridge but includes two distinct functions: Attest and Transfer.
Attestation
Attestation involves 'registering' a token with the token bridge. Before being transferred, tokens must first be attested on their Origin Chain and have corresponding wrapped tokens created on the Foreign Chain. Attesting on the Origin Chain creates requisite addresses and metadata that allow the wrapped asset to exist on Foreign Chains.
Transfer
Once attested, tokens are mapped from their Native Chain to 'wrapped' assets on the Foreign Chains. For example, transferring an Ethereum-native token to Solana results in a 'wrapped asset' on Solana. Transferring the same asset back to Ethereum restores the native token.
It's important to note that Wormhole wrapped tokens are distinct from and incompatible with tokens wrapped by other bridges. Transferring a token wrapped by a different bridge will not redeem the native token but result in a 'double-wrapped' token.
8. Extra Tutorials, Setting up with some code examples!
Before we ride on, watch this tutorial on xdapp development, setting up your coding environment.
8.1 Hello wormhole
This tutorial features the solidity contract /HelloWormhole.sol/
, deployable across multiple EVM chains to create a robust cross-chain application.
Moreover, users can also initiate their custom greeting emission on a chain, even if they lack gas funds for that particular chain!
Included steps required.
Environment Setup
Testing Locally
Deploying to Testnet
Testing on Testnet
Get directory: https://github.com/wormhole-foundation/hello-wormhole
Environment Setup
Node 16.14.1 or later, npm 8.5.0 or later: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
forge 0.2.0 or later: https://book.getfoundry.sh/getting-started/installation
Testing Locally
Get the code down from GitHub and cd into the directory, then build and test it.
git clone https://github.com/wormhole-foundation/hello-wormhole.git
cd hello-wormhole
npm run build
forge test
Here’s what is expected.
Running 1 test for test/HelloWormhole.t.sol:HelloWormholeTest
[PASS] testGreeting() (gas: 777229)
Test result: ok. 1 passed; 0 failed; finished in 3.98s
Deploying to Testnet
At least 0.05 Testnet AVAX and 0.01 Testnet CELO should be available in your active wallet.
EVM_PRIVATE_KEY=your_wallet_private_key npm run deploy
Testing on Testnet
For is you will need a wallet with at least 0.02 Testnet AVAX.
You must have also deployed contracts onto testnet (as described in the above section). To test sending and receiving a message on testnet, execute the test as such:
EVM_PRIVATE_KEY=your_wallet_private_key npm run test
Full Cross-chain HelloWormhole solidity contract
See the full implementation of the HelloWormhole.sol contract and the full Github repository with testing infrastructure
8.2 Wormhole SDK Coding example
Consider a practical example of using the Wormhole SDK to transfer your custom token from a Solana Wallet to an Ethereum Wallet. This involves two main steps:
Step 1: Register your token on the Ethereum network. This ensures that the Ethereum Wallet recognizes and interacts effectively with your token.
Step 2: Transfer and redeem your token via the Wormhole Token Bridge. Send the desired amount of your token to the Wormhole Token Bridge in Solana, which acts as an intermediary for secure token transfer between the Solana and Ethereum networks. Then, redeem your token on the Ethereum network to access and utilize it within your Ethereum Wallet.
Remember the SDK can currently be found in the core wormhole repository ( https://github.com/wormhole-foundation/wormhole/tree/main/sdk/js )
And is available on npm.
The SDK can be installed using npm :
npm i @certusone/wormhole-sdk
For detailed guidance on using the Wormhole SDK, refer to the code provided below:
To Import
import { Connection, Keypair, PublicKey, clusterApiUrl } from'@solana/web3.js';
import { ethers } from 'ethers';
import {
CHAIN_ID_ETH,
CHAIN_ID_SOLANA,
CONTRACTS,
attestFromSolana,
createWrappedOnEth,
getEmitterAddressSolana,
getIsTransferCompletedEth,
parseSequenceFromLogSolana,
redeemOnEth,
transferFromSolana,
tryNativeToUint8Array,
} from '@certusone/wormhole-sdk';
import {
getAssociatedTokenAddress,
} from '@solana/spl-token';
For Constant
// Solana constant
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
const SOLANA_SPL_TOKEN = new Publickey('HyC6H4E2sEJGQoVMhapw1WLnSb51Mnapeh3Eqke68WCM'); // SPL Token publicKey in Solana Devnet
// Keypair that you sign the transaction from Solana
const keypair = Keypair.fromSecretKey(
Uint8Array.from([
13, 82, 117, 67, 249, 64, 150, 31, 116, 67, 234, 152, 255, 109, 62, 111,
35, 170, 11, 56, 65, 18, 157, 242, 80, 97, 246, 84, 1, 65, 149, 181, 67,
249, 215, 33, 158, 135, 96, 152, 226, 28, 89, 211, 255, 248, 42, 118, 35,
1, 14, 106, 86, 195, Ï183, 2, 96, 13, 139, 199, 238, 239, 157, 74,
])
); // Your keypair
// Ethereum constant
const ETH_NODE_URL = ''; // Websocket link from Alchemy
const ETH_PRIVATE_KEY = 'Your private key'
const provider = new ethers.providers.WebSockerProvider(ETH_NODE_URL);
const signer = new ethers.Wallet(ETH_PRIVATE_KEY);
// Wormhole
const WORMHOLE_RPC_HOST = 'https://wormhole-v2-testnet-api.certus.one';
const SOL_BRIDGE_ADDRESS = new PublicKey(CONTRACTS.TESTNET.solana.core);
const SOL_TOKEN_BRIDGE_ADDRESS = new PublicKey(CONTRACTS.TESTNET.solana.token_bridge);
const ETH_TOKEN_BRIDGE_ADDRESS = CONTRACTS.TESTNET.ethereum.token_bridge;
Attest
- Solana to Ethereum
// Submit transaction - results in a Wormhole message being published
const transaction = await attestFromSolana(
connection,
SOL_BRIDGE_ADDRESS,
SOL_TOKEN_BRIDGE_ADDRESS,
payerAddress,
mintAddress
);
const signed = await wallet.signTransaction(transaction);
const txid = await connection.sendRawTransaction(signed.serialize());
await connection.confirmTransaction(txid);
// Get the sequence number and emitter address required to fetch the signedVAA of our message
const info = await connection.getTransaction(txid);
const sequence = parseSequenceFromLogSolana(info);
const emitterAddress = await getEmitterAddressSolana(SOL_TOKEN_BRIDGE_ADDRESS);
// Fetch the signedVAA from the Wormhole Network (this may require retries while you wait for confirmation)
const { signedVAA } = await getSignedVAA(
WORMHOLE_RPC_HOST,
CHAIN_ID_SOLANA,
emitterAddress,
sequence
);
// Create the wrapped token on Ethereum
await createWrappedOnEth(ETH_TOKEN_BRIDGE_ADDRESS, signer, signedVAA);
Transfer
- Solana to Ethereum
// Submit transaction - results in a Wormhole message being published
const transaction = await transferFromSolana(
connection,
SOL_BRIDGE_ADDRESS,
SOL_TOKEN_BRIDGE_ADDRESS,
payerAddress,
fromAddress,
mintAddress,
amount,
targetAddress,
CHAIN_ID_ETH,
originAddress,
originChain
);
const signed = await wallet.signTransaction(transaction);
const txid = await connection.sendRawTransaction(signed.serialize());
await connection.confirmTransaction(txid);
// Get the sequence number and emitter address required to fetch the signedVAA of our message
const info = await connection.getTransaction(txid);
const sequence = parseSequenceFromLogSolana(info);
const emitterAddress = await getEmitterAddressSolana(SOL_TOKEN_BRIDGE_ADDRESS);
// Fetch the signedVAA from the Wormhole Network (this may require retries while you wait for confirmation)
const { signedVAA } = await getSignedVAA(
WORMHOLE_RPC_HOST,
CHAIN_ID_SOLANA,
emitterAddress,
sequence
);
// Redeem on Ethereum
await redeemOnEth(ETH_TOKEN_BRIDGE_ADDRESS, signer, signedVAA);
9. Project ideas to build with wormhole
For developers seeking inspiration, here are some project ideas to explore within the Wormhole ecosystem:
Cross-Chain NFT Swapping Platform:
Develop a platform that allows users to swap NFTs seamlessly across different blockchain networks using Wormhole as the underlying bridge protocol.
Decentralized Cross-Chain Asset Management Solution:
Create a decentralized asset management solution that enables users to manage their digital assets across multiple blockchains, leveraging Wormhole for interoperability and asset transfers.
Cross-Chain Token Bridge:
Build a token bridge that facilitates the seamless transfer of tokens between different blockchain networks, powered by the Wormhole protocol, to enhance liquidity and accessibility for users.
Interoperable Decentralized Identity Platform:
Develop a decentralized identity platform that enables users to maintain their identities across multiple blockchain networks, ensuring interoperability and data portability using Wormhole as the interoperability layer.
10. Pros and Cons
Despite the immersive solutions wormhole provides, I did help to notice that there are pros and cons, let’s explore them:
Pros:
Comprehensive Interoperability: Wormhole supports a wide range of blockchains, enabling extensive cross-chain functionality.
Smart Contract Capabilities: Beyond asset transfers, it allows for smart contract calls to be made across chains, opening up possibilities for complex decentralized applications.
Security: Underpinned by a network of validator nodes, Wormhole provides a secure conduit for cross-chain transactions.
Robust Grant Scheme: Wormhole offers a substantial grant program to encourage developers to build on its platform, fostering innovation and supporting the ecosystem's growth.
Cons:
Technical Complexity: The sophisticated features of Wormhole demand significant technical expertise for development, integration, and ongoing maintenance.
Resource Intensive: Implementing and running Wormhole can be resource-intensive, requiring more infrastructure and developer time compared to simpler protocols.
11. Conclusion & Final Thoughts
Wormhole offers a gateway to a new era of blockchain interoperability and collaboration. By bridging the gap between disparate ecosystems and enabling cross-chain communication, Wormhole empowers developers to create innovative solutions and users to access decentralized services seamlessly across multiple blockchains.
Its architecture, comprising on-chain and off-chain components, ensures the integrity and validity of messages transmitted between blockchains.
As the blockchain space continues to evolve, Wormhole stands as a beacon of interoperability, driving the adoption and advancement of decentralized technologies.
12. References
Website: wormhole.com
Wormhole discord: Discord
Wormhole Documentation: https://docs.wormhole.com/wormhole
Everstake: everstake.one/blog/wormhole-gateway-bringing-liquidity-to-cosmos
Medium: Cha4
Wormhole Foundation: https://github.com/wormhole-foundation
YouTube: https://www.youtube.com/@wormholecrypto
Wormhole GitHub: https://github.com/wormhole-foundation/wormhole
Wormhole Forums: https://forum.wormholenetwork.com/
Wormhole Blog: https://wormhole.com/blog
Wormhole for Developers: https://wormhole.com/developers/