Quickstart
Garden SDK is a set of packages that aims to quickly and seamlessly swap your cross-chain assets.
Swapping your BTC to WBTC
Swapping from BTC to WBTC will only require two things from you:
- A Bitcoin private key
- An Ethereum private key
The code snippet below swaps your BTC to WBTC on Ethereum. To understand what's happening at each step, take a look at Swapping from BTC to WBTC.
import {
BitcoinNetwork,
BitcoinWallet,
BitcoinProvider,
EVMWallet,
} from "@catalogfi/wallets";
import {
Orderbook,
Chains,
Assets,
Actions,
parseStatus,
TESTNET_ORDERBOOK_API
} from "@gardenfi/orderbook";
import { GardenJS } from "@gardenfi/core";
import { JsonRpcProvider, Wallet } from "ethers";
// Option 1: Create a bitcoin wallet from a private key
const bitcoinWallet = BitcoinWallet.fromPrivateKey(
"Your PK",
new BitcoinProvider(BitcoinNetwork.Mainnet)
);
// Option 2: Create a bitcoin wallet from a WIF key
const bitcoinWallet = BitcoinWallet.fromWIF(
"Your WIF",
new BitcoinProvider(BitcoinNetwork.Mainnet)
);
// create your evm wallet
const signer = new Wallet("Your PK", new JsonRpcProvider("https://rpc.ankr.com/eth"));
const evmWallet = new EVMWallet(signer);
(async () => {
const orderbook = await Orderbook.init({
url: TESTNET_ORDERBOOK_API, // add this line only for testnet
signer,
});
const wallets = {
[Chains.bitcoin]: bitcoinWallet,
[Chains.ethereum]: evmWallet,
};
const garden = new GardenJS(orderbook, wallets);
const sendAmount = 0.0001 * 1e8;
const receiveAmount = (1 - 0.3 / 100) * sendAmount;
const orderId = await garden.swap(
Assets.bitcoin.BTC,
Assets.ethereum.WBTC,
sendAmount,
receiveAmount
);
garden.subscribeOrders(await evmWallet.getAddress(), async (orders) => {
const order = orders.filter((order) => order.ID === orderId)[0];
if (!order) return;
const action = parseStatus(order);
if (action === Actions.UserCanInitiate || action === Actions.UserCanRedeem) {
const swapper = garden.getSwap(order);
const swapOutput = await swapper.next();
console.log(
`Completed Action ${swapOutput.action} with transaction hash: ${swapOutput.output}`
);
}
});
})();
Guides
Check out our guides to help you get started on swapping your assets.
📄️ Creating Wallets
Learn how to create wallets using the @catalogfi/wallets package
📄️ Swapping from BTC to WBTC
Swap BTC to WBTC
📄️ Swapping from WBTC to BTC
Swap WBTC to BTC
📄️ 1inch Integration
Integrate 1inch into your app to swap anything to BTC or vice versa
Learn more about Garden SDK
Learn more about the Garden SDK by exploring the supported assets, chains, and underlying concepts.
📄️ Core Concepts
Learn how swapping works under the hood
📄️ Supported Chains
Find out all the supported chains & assets supported by Garden SDK