Create a Spoke Provider
This guide provides comprehensive instructions for creating spoke providers for all supported chain types in the Sodax SDK. A spoke provider is a container that combines a wallet provider with chain-specific configuration, enabling interaction with Sodax features on different blockchains.
What is a Spoke Provider?
A Spoke Provider is an instance that contains:
A wallet provider implementation (e.g.,
IEvmWalletProvider,ISuiWalletProvider) that handles wallet interactionsA chain configuration object that contains chain-specific settings, addresses, and metadata
The spoke provider acts as the bridge between your application and the Sodax protocol, allowing you to interact with swaps, money market operations, bridging, and staking features.
Important: You should create one spoke provider instance for each user wallet connection. Once created, reuse the same spoke provider instance for all Sodax feature interactions on that specific chain.
For more information, refer to the README.md section.
What is a Raw Spoke Provider?
A Raw Spoke Provider is a special type of spoke provider that is used when you only have a user's wallet address and cannot create a full wallet provider instance. Unlike regular spoke providers, raw spoke providers:
Do not require a wallet provider - They only need the user's wallet address
Cannot sign transactions - They are read-only and used for generating raw transaction data
Return raw transaction data - When used with Sodax features, they return unsigned transaction payloads instead of executing transactions
When to Use Raw Spoke Providers
Raw spoke providers are ideal for:
Backend services - When creating transaction payloads on the server side where wallet providers cannot be instantiated
Transaction preparation - When you need to prepare raw transaction data for users to sign later
Gas estimation - When estimating transaction costs without executing transactions
Multi-step flows - When separating transaction creation from transaction signing/execution
Key Differences from Regular Spoke Providers
Wallet Provider
Required (full implementation)
Not required (only address needed)
Transaction Signing
Can sign and execute
Cannot sign (read-only)
Return Type
Transaction hash (string)
Raw transaction data object
Use Case
Frontend/browser with wallet
Backend/server-side preparation
Note: When using raw spoke providers with Sodax features, you must pass the raw: true flag to methods like createIntent(), supply(), etc. This ensures the methods return raw transaction data instead of attempting to execute transactions.
Prerequisites
Before creating a spoke provider, ensure you have:
A wallet provider implementation for your target chain. You can use existing wallet provider implementations from the
@sodax/wallet-sdk-corenpm package, or use the local package @wallet-sdk-core if working within the Sodax monorepo.The
@sodax/sdkpackage installedFor Node.js environments: RPC URLs for the chains you're interacting with (we recommend using dedicated node providers like Alchemy, QuickNode, etc.)
For browser environments: Wallet extensions installed and connected (e.g., MetaMask for EVM chains)
Getting Chain Configuration
Chain configurations are available through the spokeChainConfig object exported from @sodax/sdk. This object contains pre-configured settings for all supported chains.
Note: It's recommended to initialize Sodax before creating spoke providers to ensure you have the latest chain configurations:
EVM Chains
EVM chains include Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Lightlink, and HyperEVM. For these chains, use the EvmSpokeProvider class.
Supported EVM Chains:
Arbitrum (
ARBITRUM_MAINNET_CHAIN_ID)Avalanche (
AVALANCHE_MAINNET_CHAIN_ID)Base (
BASE_MAINNET_CHAIN_ID)BSC (
BSC_MAINNET_CHAIN_ID)Optimism (
OPTIMISM_MAINNET_CHAIN_ID)Polygon (
POLYGON_MAINNET_CHAIN_ID)Lightlink (
LIGHTLINK_MAINNET_CHAIN_ID)HyperEVM (
HYPEREVM_MAINNET_CHAIN_ID)
Constructor Signature
Node.js Example
Browser Example
Raw Spoke Provider
For backend scenarios where you only have a user's wallet address and cannot create a wallet provider, use EvmRawSpokeProvider.
Constructor Signature
Example
Note: When using EvmRawSpokeProvider with Sodax features, pass raw: true to get raw transaction data instead of executing transactions.
Sonic Chain (Special Case)
Important: Sonic chain must use SonicSpokeProvider instead of EvmSpokeProvider, even though it's an EVM-compatible chain. This is because Sonic is the hub chain of the Sodax protocol and requires special handling.
Constructor Signature
Example
Raw Spoke Provider
For backend scenarios where you only have a user's wallet address, use SonicRawSpokeProvider.
Constructor Signature
Example
Sui Chain
For Sui blockchain, use the SuiSpokeProvider class.
Note: The constructor parameter order is different from EVM chains - chain configuration comes first, then wallet provider.
Constructor Signature
Node.js Example
Browser Example
Raw Spoke Provider
For backend scenarios where you only have a user's wallet address, use SuiRawSpokeProvider.
Note: The constructor parameter order is the same as the regular provider - chain configuration comes first, then wallet address.
Constructor Signature
Example
Stellar Chain
For Stellar blockchain, use the StellarSpokeProvider class. Stellar uses both Horizon (for account data) and Soroban RPC (for smart contract interactions).
Constructor Signature
RPC Configuration
The optional rpcConfig parameter allows you to specify custom Horizon and Soroban RPC URLs:
If not provided, the RPC URLs from chainConfig will be used.
Node.js Example
Browser Example
Raw Spoke Provider
For backend scenarios where you only have a user's wallet address, use StellarRawSpokeProvider.
Constructor Signature
Example
Injective Chain
For Injective blockchain, use the InjectiveSpokeProvider class.
Note: The constructor parameter order is different from EVM chains - chain configuration comes first, then wallet provider.
Constructor Signature
Node.js Example
Browser Example
Raw Spoke Provider
For backend scenarios where you only have a user's wallet address, use InjectiveRawSpokeProvider.
Note: The constructor parameter order is the same as the regular provider - chain configuration comes first, then wallet address.
Constructor Signature
Example
ICON Chain
For ICON blockchain, use the IconSpokeProvider class.
Constructor Signature
Node.js Example
Browser Example
Raw Spoke Provider
For backend scenarios where you only have a user's wallet address, use IconRawSpokeProvider.
Note: The constructor parameter order differs from the regular provider - chain configuration comes first, then wallet address.
Constructor Signature
Example
Solana Chain
For Solana blockchain, use the SolanaSpokeProvider class.
Constructor Signature
Node.js Example
Browser Example
Raw Spoke Provider
For backend scenarios where you only have a user's wallet address, use SolanaRawSpokeProvider. This provider also provides additional utility methods for building transactions and querying balances.
Constructor Signature
Example
Note: SolanaRawSpokeProvider provides additional methods like buildV0Txn(), getBalance(), getTokenAccountBalance(), and getAssociatedTokenAddress() through its walletProvider interface.
Best Practices
One Spoke Provider Per Wallet Connection
Create one spoke provider instance for each user wallet connection. Once created, reuse the same spoke provider instance for all operations on that chain:
Initialize Sodax Before Creating Spoke Providers
Initialize Sodax before creating spoke providers to ensure you have the latest chain configurations:
Handle Wallet Disconnection
When a user disconnects their wallet, you should recreate the spoke provider when they reconnect:
Type Safety
Always use proper TypeScript types when creating spoke providers to ensure type safety:
Usage Examples
Once you've created a spoke provider, you can use it with all Sodax features:
Using with Swaps
For detailed swap documentation, see HOW_TO_MAKE_A_SWAP.md and SWAPS.md.
Using Raw Spoke Providers with Swaps
When using raw spoke providers, you must pass the raw: true flag to get raw transaction data instead of executing transactions:
Key differences when using raw spoke providers:
Return type is a raw transaction data object
{ from, to, value, data }instead of a transaction hashTransactions are not executed automatically
Useful for backend services that prepare transactions for frontend signing
Can be used for gas estimation without executing transactions
Using with Money Market
For detailed money market documentation, see MONEY_MARKET.md.
Using with Bridge
For detailed bridge documentation, see BRIDGE.md.
Using with Staking
For detailed staking documentation, see STAKING.md.
Summary
Spoke Provider is a container that combines wallet provider and chain configuration
Raw Spoke Provider is used when only a wallet address is available (backend scenarios, transaction preparation)
Create one spoke provider per wallet connection and reuse it for all operations
Use the appropriate provider class for each chain type:
Regular Spoke Providers (require full wallet provider):
EvmSpokeProviderfor EVM chains (Arbitrum, Polygon, BSC, etc.)SonicSpokeProviderfor Sonic chain (special case - hub chain)SuiSpokeProviderfor Sui blockchainStellarSpokeProviderfor Stellar blockchainInjectiveSpokeProviderfor Injective blockchainIconSpokeProviderfor ICON blockchainSolanaSpokeProviderfor Solana blockchain
Raw Spoke Providers (only require wallet address):
EvmRawSpokeProviderfor EVM chainsSonicRawSpokeProviderfor Sonic chainSuiRawSpokeProviderfor Sui blockchainStellarRawSpokeProviderfor Stellar blockchainInjectiveRawSpokeProviderfor Injective blockchainIconRawSpokeProviderfor ICON blockchainSolanaRawSpokeProviderfor Solana blockchain
When to use Raw Spoke Providers:
Backend services creating transaction payloads
Transaction preparation without signing
Gas estimation without execution
Multi-step flows separating creation from signing
When to use Regular Spoke Providers:
Frontend/browser applications with wallet connections
When you need to sign and execute transactions
Interactive user flows
Initialize Sodax before creating spoke providers for latest configuration
Use proper TypeScript types for type safety
Reuse the same spoke provider instance for all operations on that chain
When using raw spoke providers with Sodax features, always pass
raw: trueto get raw transaction data
For more information on specific features, refer to the respective documentation files:
HOW_TO_MAKE_A_SWAP.md - Swap operations
SWAPS.md - Swap API reference
MONEY_MARKET.md - Money market operations
BRIDGE.md - Bridge operations
STAKING.md - Staking operations
Last updated