Get Started with the TypeScript SDK#
Introduction#
The Wormhole TypeScript SDK provides a unified, type-safe interface for building cross-chain applications. It is a foundational toolkit that supports interaction with core Wormhole protocols, including Native Token Transfers, Token Bridge, CCTP, and Settlement, giving developers a consistent API across multiple chains.
This guide helps you install the SDK, initialize a Wormhole
instance to support your desired network and blockchain platforms, and return chain-specific information to verify successful initialization.
If you want to build more advanced integrations, such as token transfers using the Token Bridge or CCTP Bridge, skip ahead to Next Steps.
Install the SDK#
To install the Wormhole TypeScript SDK, use the following command:
This package combines all the individual packages to make setup easier.
You can choose to install a specific set of packages as needed. For example, to install EVM-specific utilities, you can run:
Complete list of individually published packages
Platform-Specific Packages
@wormhole-foundation/sdk-evm
@wormhole-foundation/sdk-solana
@wormhole-foundation/sdk-algorand
@wormhole-foundation/sdk-aptos
@wormhole-foundation/sdk-cosmwasm
@wormhole-foundation/sdk-sui
Protocol-Specific Packages
-
Core Protocol
@wormhole-foundation/sdk-evm-core
@wormhole-foundation/sdk-solana-core
@wormhole-foundation/sdk-algorand-core
@wormhole-foundation/sdk-aptos-core
@wormhole-foundation/sdk-cosmwasm-core
@wormhole-foundation/sdk-sui-core
-
Token Bridge
@wormhole-foundation/sdk-evm-tokenbridge
@wormhole-foundation/sdk-solana-tokenbridge
@wormhole-foundation/sdk-algorand-tokenbridge
@wormhole-foundation/sdk-aptos-tokenbridge
@wormhole-foundation/sdk-cosmwasm-tokenbridge
@wormhole-foundation/sdk-sui-tokenbridge
-
CCTP
@wormhole-foundation/sdk-evm-cctp
@wormhole-foundation/sdk-solana-cctp
@wormhole-foundation/sdk-aptos-cctp
@wormhole-foundation/sdk-sui-cctp
-
Other Protocols
@wormhole-foundation/sdk-evm-portico
@wormhole-foundation/sdk-evm-tbtc
@wormhole-foundation/sdk-solana-tbtc
Utility Packages
@wormhole-foundation/sdk-base
@wormhole-foundation/sdk-definitions
@wormhole-foundation/sdk-connect
Initialize the SDK#
Getting your integration started is simple. First, import Wormhole:
Then, import each of the ecosystem platforms that you wish to support:
import algorand from '@wormhole-foundation/sdk/algorand';
import aptos from '@wormhole-foundation/sdk/aptos';
import cosmwasm from '@wormhole-foundation/sdk/cosmwasm';
import evm from '@wormhole-foundation/sdk/evm';
import solana from '@wormhole-foundation/sdk/solana';
import sui from '@wormhole-foundation/sdk/sui';
To make the platform modules available for use, pass them to the Wormhole constructor and specify the network (Mainnet
, Testnet
, or Devnet
) you want to interact with:
With a configured Wormhole
object, you can begin to interact with these chains.
Example Usage#
Follow these steps to confirm that the SDK is initialized correctly and can fetch basic chain information for your target chains.
Prerequisites#
Before you begin, make sure you have the following:
- Node.js and npm installed
- TypeScript installed
Project setup instructions
Use the following commands to create a TypeScript project:
-
Create a directory and initialize a Node.js project:
-
Install TypeScript,
tsx
(for running TypeScript files), Node.js type definitions, the base Wormhole SDK, and the platform-specific packages for the chains you want to interact with: -
Create a
tsconfig.json
if you don't have one. You can generate a basic one using the following command:Make sure your
tsconfig.json
includes the following settings: -
Initialize the main
Wormhole
class to use the SDK. Create a new TypeScript file namedsrc/main.ts
in your project directory: -
Add the following code to initialize the SDK and use the
Wormhole
instance to return the chain ID and RPC for the chains this instance supports:src/main.tsimport { wormhole } from '@wormhole-foundation/sdk'; // Import specific platform modules for the chains you intend to use import evm from '@wormhole-foundation/sdk/evm'; import solana from '@wormhole-foundation/sdk/solana'; async function main() { console.log('Initializing Wormhole SDK...'); // Determine the network: "Mainnet", "Testnet", or "Devnet" const network = 'Testnet'; // Initialize the SDK with the chosen network and platform contexts const wh = await wormhole(network, [evm, solana]); console.log('Wormhole SDK Initialized!'); } main().catch((e) => { console.error('Error initializing Wormhole SDK', e); process.exit(1); });
Fetch Chain Information#
-
Update the
main
function as follows to retrieve the chain ID and RPC for the chains your project supports:src/main.tsimport { wormhole } from '@wormhole-foundation/sdk'; import evm from '@wormhole-foundation/sdk/evm'; import solana from '@wormhole-foundation/sdk/solana'; async function main() { console.log('Initializing Wormhole SDK...'); const network = 'Testnet'; const wh = await wormhole(network, [evm, solana]); console.log('Wormhole SDK Initialized!'); // Example: Get a chain ID and RPC for Solana const solanaDevnetChain = wh.getChain('Solana'); console.log( `Chain ID for Solana Testnet: ${solanaDevnetChain.config.chainId}` ); console.log(`RPC for Solana Testnet: ${solanaDevnetChain.config.rpc}`); // Example: Get a chain ID for Sepolia (EVM Testnet) const sepoliaChain = wh.getChain('Sepolia'); console.log(`Chain ID for Sepolia: ${sepoliaChain.config.chainId}`); console.log(`RPC for Sepolia: ${sepoliaChain.config.rpc}`); } main().catch((e) => { console.error( 'Error initializing Wormhole SDK or fetching chain information:', e ); process.exit(1); });
-
Run the script with the following command, replacing
INSERT_FILE_NAME
with your file name:You will see terminal output similar to the following:
npx tsx src/main.ts Initializing Wormhole SDK... Wormhole SDK Initialized! Chain ID for Solana Testnet: 1 RPC for Solana Testnet: https://api.devnet.solana.com Chain ID for Sepolia: 10002 RPC for Sepolia: https://ethereum-sepolia.publicnode.com
Congratulations! You’ve successfully installed the Wormhole TypeScript SDK and initialized a Wormhole
instance. Consider the following options to build on what you've accomplished.
Next Steps#
- Get familiar with the SDK
- Send a multichain message
- Transfer assets via the Token Bridge
- Transfer USDC via the CCTP Bridge