Local Development Guide

This guide is for developers that want to make some changes on the Glittr Core, Glittr SDK, or the Wallet Extension. Often times you want to test your changes end-to-end, and that means you'll have to setup the whole Glittr setup locally.

Before we get into the guide, let's look at the overall flow. An end-to-end flow would look like this:

  1. User install and use Glittr Wallet

  2. User opens an application that uses glittr-sdk to build Glittr transaction

  3. That application will use Electrum API to broadcast a transaction

  4. After a transaction is broadcasted, it will be mined by a local Bitcoin node

  5. After it is mined, the transaction will be processed by the Glittr node

  6. The result of that processing will be reflected on the app and the wallet

This tutorial will guide you through the entire flow, entirely locally. So you can make changes and test end-to-end.

Table of Contents

1. Install bitcoind and run a local devnet bitcoin node

2. Install and run a Glittr node

3. Build and run electrum server

4. Build and run explorer

5. Build and run glittr-sdk

6. Building and running Example App

7. Building and using Glittr Wallet

1. Install bitcoind and run a local devnet bitcoin node

First, follow the tutorial here to install the bitcoin node Run a Bitcoin Node and start it running for local development.

Open up another terminal and then run the command below:

After that, you probably want to mine the blocks automatically. Create a new file and paste the script below:

You will need to change the permissions to make the script executable, run:

Then run the script:

You can send Bitcoin to your address by using the bitcoin-cli, you'll find your Bitcoin address after you have your wallet.

If this your first time running bitcoind, generate 100 blocks as requirement for the coinbase maturity rulearrow-up-right:

If you are following correctly, the bitcoin will open an RPC port at 127.0.0.1:18443, and the Glittr node will open up a port at 127.0.0.1:3001.

2. Install and run a Glittr node

And then follow this tutorial to run the Glittr node Run a Glittr Node. Make sure that the settings.yml use the correct Bitcoin rpc.

3. Build and run electrum server

Electrum is used to broadcast bitcoin transactions without directly using a bitcoin RPC. It's also used in wallets.

Open a new terminal and clone https://github.com/Glittrfi/electrsarrow-up-right. Make sure rust is installedarrow-up-right.

Make sure the bitcoin node already running, move to the directory where you installed Electrum and then do this to run the Electrum service:

The process will open a port at 127.0.0.1:3000. So now you'll have the following services,

Service
URL

Bitcoin RPC

127.0.0.1:18443

Glittr Core API

127.0.0.1:3001

Electrum API

127.0.0.1:3000

4. Build and run explorer

To run explorer on your local machine, first clone this repository https://github.com/Glittrfi/BTC-RPC-Explorerarrow-up-right. Make sure you have install node (https://nodejs.org/en/downloadarrow-up-right).

Change the directory to the cloned repository, and run this to install dependencies

Create a file named .env edit the endpoints according to your local ports

To start the explorer, run

Open the explorer at http://127.0.0.1:8080.

5. Build and run glittr-sdk

Clone the repository https://github.com/Glittrfi/glittr-sdk-publicarrow-up-right. This is a typescript library, so make sure you have install node (https://nodejs.org/en/downloadarrow-up-right). This library will be imported by frontend apps, and also the wallet extension.

We're mostly using yarn as package manager, so let's install yarn.

Go to the glittr-sdk-public directory and install the dependencies

This project is a monorepo, so try to build the whole packages

The glittr-sdk package is inside packages/sdk, and we have some tests available at apps/sdk-test. Let's create a new file inside apps/sdk-test/src let's name this file free-mint.ts . This file will create a new contract for free mint.

This example has a hardcoded Bitcoin wallet, let's see what's the address is (let's use the P2PKH addressarrow-up-right)

Let's do yarn buildand then node apps/sdk-test/dist/check-address.js . You will see that the address is "mroHGEtVBLxKoo34HSHbHdmKz1ooJdA3ew". Now send some Bitcoin to that address:

Wait for a bit (a minute for a block to be mined). And then yarn buildand run the free-mint example from above `node apps/sdk-test/dist/free-mint.js` . If you see your transaction ID, that means you have created a Glittr contract, congrats!

6. Building and running Example App

Let's use the glittr boilerplate app. Clone the repo at https://github.com/Glittrfi/glittr-examplesarrow-up-right. Let's go to the glittr-free-mint-vite-react. Do the following to install dependencies and test build.

Change the .env.local to your local setting

Run yarn devto test the app locally, it might open a port at http://localhost:5173.

NOTE: If you want to test your edited glittr-sdk , you can use yarn link.

  1. Inside glittr-sdk/packages/sdkdo yarn link , ensure that you have run yarn build

  2. Go to the glittr example directory, do yarn link @glittr-sdk/sdk

  3. Your app project is now using the local glittr-sdk

7. Building and using Glittr Wallet

If you want to make changes to the wallet, you can first clone the https://github.com/Glittrfi/wallet-extensionarrow-up-right. Install the required dependencies:

Change the endpoints inside src/shared/constant/index.ts, on line 369-387 change the devnet endpoints. When you are using the wallet, select Devnet, just put anything for the Api Key since we are on local.

Make some changes and then build for chrome:

For firefox:

For brave:

The build result would be inside dist/ directory. Install the wallet by following this tutorial Installing Glittr Wallet. After you make some changes again, you can do this for chrome to build the extension faster,

You can then refresh the chrome extension to reflect the changes.

Last updated