The glittr SDK is a client-side library written in Typescript designed to provide seamless access to the comprehensive Glittr infrastructure and ecosystem. It facilitates interaction with various glittr services by offering a simplified API that streamlines the integration process, allowing developers to efficiently leverage glittr's tools within their applications.
By utilizing this library, developers can build, manage, and deploy rich applications on Bitcoin using the cutting-edge Glittr infrastructure.
Prerequisites:
Installation with npm
Copy npm install @glittr-sdk/sdk
Installation with yarn
Copy yarn add @glittr-sdk/sdk
Usage
Init SDK
Javascript
Copy const { GlittrSDK } = require ( "@glittr-sdk/sdk" );
const NETWORK = "regtest" ;
const client = new GlittrSDK ({
network : NETWORK ,
electrumApi : "https://hackathon-electrum.glittr.fi" ,
glittrApi : "https://hackathon-core-api.glittr.fi" ,
});
consoel .log (client)
Typescript/ES6
Copy import { GlittrSDK } from "@glittr-sdk/sdk" ;
const NETWORK = "regtest" ;
const client = new GlittrSDK ({
network : NETWORK ,
electrumApi : "https://hackathon-electrum.glittr.fi" ,
glittrApi : "https://hackathon-core-api.glittr.fi" ,
});
consoel .log (client)
Load Account
Import Bitcoin account using private key hex:
Copy import { Account } from "@glittr-sdk/sdk" ;
const NETWORK = "regtest" ;
const account = new Account ({
privateKey : "your bitcoin private key" ,
network : NETWORK
})
console .log ( account .p2pkh ())
console .log ( account .p2wpkh ())
Or using WIF (Wallet Import Format) text
Copy 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
Copy import { txBuilder } from "@glittr-sdk/sdk" ;
const c = txBuilder .freeMintContractInstantiate ({
simple_asset : {
supply_cap : 2000 n .toString () ,
divisibility : 18 ,
live_time : 0 ,
} ,
amount_per_mint : 2 n .toString () ,
});
console .log (c)
Example Create and Send Glittr Transaction
Freemint Contract Creation
Copy import { Account , GlittrSDK , txBuilder } from "@glittr-sdk/sdk" ;
async function main () {
const NETWORK = "regtest" ;
const client = new GlittrSDK ({
network : NETWORK ,
electrumApi : "https://hackathon-electrum.glittr.fi" ,
glittrApi : "https://hackathon-core-api.glittr.fi" ,
});
const account = new Account ({
wif : "your WIF text" ,
network : NETWORK ,
});
const c = txBuilder .freeMintContractInstantiate ({
simple_asset : {
supply_cap : 2000 n .toString () ,
divisibility : 18 ,
live_time : 0 ,
} ,
amount_per_mint : 2 n .toString () ,
});
const txid = await client .createAndBroadcastTx ({
account : account .p2pkh () ,
tx : c ,
outputs : []
});
console .log ( "TXID : " , txid);
}
main ();