A script for demonstrating cross-chain asset swaps between Starknet and Bitcoin using Garden Finance protocol. This project demonstrates how to perform atomic swaps between Starknet WBTC and Bitcoin BTC on testnet.
- 🔄 Cross-chain swaps: Exchange assets between Starknet and Bitcoin networks
- 🛡️ Atomic swaps: Secure HTLC-based transactions with automatic redemption
- 📊 Real-time quotes: Get live pricing and availability for supported assets
- 🔍 Order tracking: Monitor transaction status through Garden Finance explorer
- ⚡ Gasless initiation: Starknet-to-Bitcoin swaps use gasless transaction initiation
- Bun runtime (recommended) or Node.js
- TypeScript knowledge
- Starknet wallet with testnet funds
- Bitcoin testnet wallet (for Bitcoin-to-Starknet swaps)
garden-app-id: 47d589e79ffbe321d296609f63922e64953da28ba08e07a7f4ba2d7978cfb931
Use this to access protected routes (Create Order & Action)
- Clone the repository:
git clone <repository-url>
cd resolve-starknet- Install dependencies:
bun install- Copy the sample configuration:
cp sample_config.json config.json- Update
config.jsonwith your details:
{
"starknetNodeUrl": "https://starknet-sepolia.public.blastapi.io",
"starknetAddress": "YOUR_STARKNET_ADDRESS",
"starknetPrivateKey": "YOUR_STARKNET_PRIVATE_KEY",
"orderbookURL": "https://testnet.api.garden.finance/v2",
"gardenAppId": "47d589e79ffbe321d296609f63922e64953da28ba08e07a7f4ba2d7978cfb931",
"bitcoinAddress": "YOUR_BITCOIN_ADDRESS"
}starknetNodeUrl: Starknet RPC endpoint (Sepolia testnet)starknetAddress: Your Starknet wallet addressstarknetPrivateKey: Your Starknet private keyorderbookURL: Garden Finance API endpointgardenAppId: Application ID for Garden Finance APIbitcoinAddress: Your Bitcoin testnet address
Execute the main script to perform a Starknet WBTC to Bitcoin BTC swap:
bun run index.tsThe script demonstrates a complete cross-chain swap flow:
- Get Supported Assets: Fetches available assets from both networks
- Get Quote: Retrieves current pricing and swap details
- Create Order: Initiates a new swap order
- Process Transaction: Handles the appropriate flow based on source network
- Create order through the API
- Pay Bitcoin to the provided HTLC address
- Wait for Bitcoin transaction confirmation
- Automatic redemption on Starknet
- Create order through the API
- Approve token spending (if required)
- Sign typed data message
- Submit signature to initiate gasless transaction
- Automatic redemption on Bitcoin
The script interacts with these Garden Finance API endpoints:
GET /assets- List supported assetsGET /quote- Get swap quotePOST /orders- Create new orderPATCH /orders/{id}?action=initiate- Initiate Starknet-to-Bitcoin swap
Monitor your swap progress:
- Explorer: https://testnet-explorer.garden.finance/order/{order_id}
- API: https://testnet.api.garden.finance/v2/orders/{order_id}
axios: HTTP client for API requestsstarknet: Starknet SDK for blockchain interactionsviem: Ethereum utilities for parsing amounts
- This is a testnet implementation - never use mainnet private keys
- Keep your private keys secure and never commit them to version control
- The
config.jsonfile should be added to.gitignore - Always verify transaction details before signing
- Insufficient Balance: Ensure you have enough WBTC on Starknet or BTC on Bitcoin testnet
- Network Issues: Check your RPC endpoint connectivity
- Invalid Configuration: Verify all addresses and keys are correct
- Transaction Failures: Check gas fees and network congestion
This project is private and proprietary.
Testnet Faucet : https://testnetbtc.com // claim testnet btc, evm, sol
For issues and questions:
- Check the Garden Finance Documentation
- Review the explorer for transaction status
- Verify your configuration matches the sample