This is an example on building a command-line interface tool using the Garden SDK. This tool lets you swap between WBTC (Wrapped Bitcoin) and BTC (Bitcoin) directly from your terminal. For a step-by-step guide on how this CLI was built, refer to cookbook/demo-cli.
Note
This example is meant to help you get started with the Garden SDK. It is not a complete or optimized tool and does not follow all best practices.
- Clone the repository.
git clone https://github.com/gardenfi/demo-cli
cd demo-cli
- Install the required dependencies.
bun install
bun link
bun link swapper
- Get the
API_KEY
. TheAPI_KEY
is used for initializing theETHEREUM_PROVIDER
.
// File: src/index.ts
// Part of the code that does the initialization
const API_KEY = readFileSync(join(homedir(), ".swapper_api_key"),"utf-8");
const RPC_PROVIDER_URL = `https://sepolia.gateway.tenderly.co/${API_KEY}`;
const ETHEREUM_PROVIDER = new JsonRpcProvider(RPC_PROVIDER_URL);
Note
Here we are using Tenderly as an RPC Provider.
-
To obtain the
API_KEY
from Tenderly,go to the Tenderly Dashboard. Navigate to Node RPCs and click Create Node & Sepolia as your network. -
Set up the
API_KEY
.
chmod +x setup_key.sh
./setup_key.sh <API_KEY>
Create an EVM wallet.
swapper createevmwallet --privatekey=<PRIVATE_KEY>
Create a Bitcoin wallet.
swapper createbitcoinwallet --privatekey=<PRIVATE_KEY>
Swap between WBTC to BTC.
swapper swapwbtctobtc --amount=0.0001
Swap between BTC to WBTC.
swapper swapbtctowbtc --amount=0.0001
A utility command useful for looking up the $HOME/.swapper_config.json
file.
swapper getdetails