Skip to main content

bridge/classes/BridgeService.md

Bridge Service - Main entry point for cross-chain operations.

Supports bridging between:

  • GalaChain ↔ Ethereum (6 tokens: GALA, GWETH, GUSDC, GUSDT, GWTRX, GWBTC)
  • GalaChain ↔ Solana (2 tokens: GALA, GSOL)

Example​

const bridgeService = new BridgeService({
galaChainWalletAddress: 'eth|1234...',
ethereumPrivateKey: '0xabcd...',
solanaPrivateKey: 'base58EncodedKey...',
bridgeableTokenService,
});

const fee = await bridgeService.estimateBridgeFee({
tokenId: 'GALA|Unit|none|none',
destinationChain: 'Ethereum',
});

Constructors​

Constructor​

new BridgeService(config): BridgeService

Parameters​

ParameterTypeDescription
configBridgeServiceConfigBridge service configuration

Returns​

BridgeService

Throws​

GalaSDKError INVALID_BRIDGE_OPTION (bridgeableTokenService) without a token lookup; INVALID_WALLET_ADDRESS (galaChainWalletAddress) for a wallet address that is not a GalaChain one; the strategies' refusals of a bad key

Methods​

bridgeIn()​

bridgeIn(params): Promise<BridgeTransaction>

Bridge tokens in from an external chain to GalaChain.

Parameters​

ParameterTypeDescription
paramsBridgeInParamsBridge in parameters

Returns​

Promise<BridgeTransaction>

Transaction details

Throws​

GalaSDKError UNSUPPORTED_BRIDGE_TOKEN for a token the chain's strategy does not bridge; the strategy's failures


bridgeOut()​

bridgeOut(params): Promise<BridgeTransaction>

Bridge tokens out from GalaChain to an external chain.

Parameters​

ParameterTypeDescription
paramsBridgeOutParamsBridge out parameters

Returns​

Promise<BridgeTransaction>

Transaction details

Throws​

GalaSDKError INVALID_WALLET_ADDRESS (recipientAddress) for a recipient that is not an address of the destination chain; UNSUPPORTED_BRIDGE_TOKEN for a token the chain's strategy does not bridge; the strategy's failures


estimateBridgeFee()​

estimateBridgeFee(params): Promise<BridgeFeeEstimate>

Estimate the fee of a bridge-out (a per-transfer cost: it does not depend on the amount).

Parameters​

ParameterTypeDescription
paramsEstimateBridgeFeeParamsToken and destination chain

Returns​

Promise<BridgeFeeEstimate>

Fee estimate


fetchEthereumWalletAllBalances()​

fetchEthereumWalletAllBalances(address?): Promise<EthereumWalletBalanceResult>

Every bridge-token balance and the ETH balance of the Ethereum wallet or address.

Parameters​

ParameterType
address?string

Returns​

Promise<EthereumWalletBalanceResult>


fetchEthereumWalletNativeBalance()​

fetchEthereumWalletNativeBalance(address?): Promise<ExternalChainBalance>

The ETH balance of the Ethereum wallet or address.

Parameters​

ParameterType
address?string

Returns​

Promise<ExternalChainBalance>


fetchEthereumWalletTokenBalance()​

fetchEthereumWalletTokenBalance(symbol, address?): Promise<ExternalChainBalance>

One ERC-20 balance of the Ethereum wallet or address, with its token's details.

Parameters​

ParameterType
symbolstring
address?string

Returns​

Promise<ExternalChainBalance>


fetchSolanaWalletAllBalances()​

fetchSolanaWalletAllBalances(address?): Promise<SolanaWalletBalanceResult>

Every bridge-token balance and the SOL balance of the Solana wallet or address.

Parameters​

ParameterType
address?string

Returns​

Promise<SolanaWalletBalanceResult>


fetchSolanaWalletNativeBalance()​

fetchSolanaWalletNativeBalance(address?): Promise<ExternalChainBalance>

The SOL balance of the Solana wallet or address.

Parameters​

ParameterType
address?string

Returns​

Promise<ExternalChainBalance>


fetchSolanaWalletTokenBalance()​

fetchSolanaWalletTokenBalance(symbol, address?): Promise<ExternalChainBalance>

One SPL balance of the Solana wallet or address, with its token's details.

Parameters​

ParameterType
symbolstring
address?string

Returns​

Promise<ExternalChainBalance>


getBridgeStatus()​

getBridgeStatus(transactionHash): Promise<BridgeStatus>

Get the status of a bridge transaction (GalaConnect tracks both chains: one read).

Parameters​

ParameterTypeDescription
transactionHashstringTransaction hash

Returns​

Promise<BridgeStatus>

Current status


getEthereumNativeBalance()​

getEthereumNativeBalance(address?): Promise<string>

The ETH balance (decimal string) of the Ethereum wallet or address.

Parameters​

ParameterType
address?string

Returns​

Promise<string>


getEthereumTokenBalance()​

getEthereumTokenBalance(tokenSymbol, address?): Promise<string>

An ERC-20 balance (decimal string) of the Ethereum wallet or address.

Parameters​

ParameterType
tokenSymbolstring
address?string

Returns​

Promise<string>


getEthereumTransactionStatus()​

getEthereumTransactionStatus(transactionHash): Promise<EthereumTransactionStatus>

The status of an Ethereum transaction, from the Ethereum RPC.

Parameters​

ParameterType
transactionHashstring

Returns​

Promise<EthereumTransactionStatus>


getSolanaNativeBalance()​

getSolanaNativeBalance(address?): Promise<string>

The SOL balance (decimal string) of the Solana wallet or address.

Parameters​

ParameterType
address?string

Returns​

Promise<string>


getSolanaTokenBalance()​

getSolanaTokenBalance(tokenSymbol, address?): Promise<string>

An SPL balance (decimal string) of the Solana wallet or address.

Parameters​

ParameterType
tokenSymbolstring
address?string

Returns​

Promise<string>


getSolanaTransactionStatus()​

getSolanaTransactionStatus(signature): Promise<SolanaTransactionStatus>

The status of a Solana transaction, from the Solana RPC.

Parameters​

ParameterType
signaturestring

Returns​

Promise<SolanaTransactionStatus>


getSupportedBridgeChains()​

getSupportedBridgeChains(): ExternalNetwork[]

Get the chains this service can bridge with (Solana only with a Solana key).

Returns​

ExternalNetwork[]


getSupportedBridgeTokens()​

getSupportedBridgeTokens(chain?): BridgeToken[]

Get the bridge tokens (for one chain, or all).

Parameters​

ParameterTypeDescription
chain?ExternalNetworkOptional chain filter

Returns​

BridgeToken[]

Supported tokens with their chains and addresses


isTokenSupported()​

isTokenSupported(tokenSymbol, chain?): boolean

Whether a token symbol is bridgeable (with chain, or with any configured chain).

Parameters​

ParameterType
tokenSymbolstring
chain?ExternalNetwork

Returns​

boolean


isValidAddress()​

isValidAddress(address, chain): boolean

Whether an address is valid for a chain (false for a chain that is not configured).

Parameters​

ParameterType
addressstring
chainExternalNetwork

Returns​

boolean


requestSolanaDevnetAirdrop()​

requestSolanaDevnetAirdrop(amount?, address?): Promise<string>

Request a devnet SOL airdrop (devnet only).

Parameters​

ParameterType
amount?number
address?string

Returns​

Promise<string>


waitForBridgeCompletion()​

waitForBridgeCompletion(transactionHash, options?): Promise<BridgeStatus>

Wait for a bridge transaction to reach a final status (completed, failed, delivery failed).

Parameters​

ParameterTypeDescription
transactionHashstringTransaction hash
options?WaitForBridgeOptionsPolling options (defaults: the service's pollInterval and pollTimeout)

Returns​

Promise<BridgeStatus>

Final status

Throws​

GalaSDKError BRIDGE_STATUS_TIMEOUT when the timeout comes first