> For the complete documentation index, see [llms.txt](https://docs.glittr.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glittr.fi/building-on-glittr/glittr-sdk.md).

# Glittr SDK

The Glittr SDK is a client-side library written in Typescript designed to facilitates interaction with the Glittr protocol, allowing developers to integrate Glittr with their dApps.&#x20;

By utilizing this library, developers can create contracts, call contracs, and transfer Glittr assets on Bitcoin using the Glittr infrastructure.

### **Prerequisites:**

Installation with npm

```
npm install @glittr-sdk/sdk
```

Installation with yarn

```
yarn add @glittr-sdk/sdk
```

### Usage

#### Init SDK

Javascript

```javascript
const { GlittrSDK } = require("@glittr-sdk/sdk");

const NETWORK = "regtest";

const client = new GlittrSDK({
  network: NETWORK,
  electrumApi: "https://devnet-electrum.glittr.fi",
  glittrApi: "https://devnet-core-api.glittr.fi",
  apiKey: "<your-api-key>"
});
console.log(client)
```

Typescript/ES6

```typescript
import { GlittrSDK } from "@glittr-sdk/sdk";

const NETWORK = "regtest";

const client = new GlittrSDK({
  network: NETWORK,
  electrumApi: "https://devnet-electrum.glittr.fi",
  glittrApi: "https://devnet-core-api.glittr.fi",
  apiKey: "<your-api-key>"
});
console.log(client)
```

#### **Load Account**

Import Bitcoin account using private key hex:

<pre class="language-typescript"><code class="lang-typescript">import { Account } from "@glittr-sdk/sdk";
<strong>
</strong>const NETWORK = "regtest";

const account = new Account({
    privateKey: "your bitcoin private key",
    network: NETWORK
})

console.log(account.p2pkh())
console.log(account.p2wpkh())
</code></pre>

Or using WIF (Wallet Import Format) text

```typescript
import { Account } from "@glittr-sdk/sdk";

const NETWORK = "regtest";

const account = new Account({
    wif: "your WIF text",
    network: NETWORK
})

console.log(account.p2pkh())
console.log(account.p2wpkh())
```

#### Construct Glittr Transaction

```typescript
import { txBuilder } from "@glittr-sdk/sdk";

const c = txBuilder.freeMintContractInstantiate({
  simple_asset: {
    supply_cap: 2000n.toString(),
    divisibility: 18,
    live_time: 0,
  },
  amount_per_mint: 2n.toString(),
});

console.log(c)
```

### Example Create and Send Glittr Transaction

#### Freemint Contract Creation

```typescript
import { Account, GlittrSDK, txBuilder } from "@glittr-sdk/sdk";

async function main() {
  const NETWORK = "regtest";

  const client = new GlittrSDK({
    network: NETWORK,
    electrumApi: "https://devnet-electrum.glittr.fi",
    glittrApi: "https://devnet-core-api.glittr.fi",
    apiKey: "<your-api-key>"
  });
  const account = new Account({
    wif: "your WIF text",
    network: NETWORK,
  });

  const c = txBuilder.freeMintContractInstantiate({
    simple_asset: {
      supply_cap: 2000n.toString(),
      divisibility: 18,
      live_time: 0,
    },
    amount_per_mint: 2n.toString(),
  });

  const txid = await client.createAndBroadcastTx({
    account: account.p2pkh(),
    tx: c,
    outputs: []
  });
  
  console.log("TXID : ", txid);
}

main();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.glittr.fi/building-on-glittr/glittr-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
