Skip to content

Commit

Permalink
feat: examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Oct 28, 2024
1 parent 9962fcf commit 18930c6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
35 changes: 35 additions & 0 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { BitcoinRpcProvider, UtuProvider } from "bitcoin-on-starknet";

async function main() {
// Initialize the Bitcoin RPC provider
const bitcoinProvider = new BitcoinRpcProvider({
url: process.env.BITCOIN_RPC_URL || "http://localhost:8332",
username: process.env.BITCOIN_RPC_USERNAME,
password: process.env.BITCOIN_RPC_PASSWORD,
});

// Initialize the Utu provider with the Bitcoin provider
const utuProvider = new UtuProvider(bitcoinProvider);

try {
// Get proof for block height 800000
console.log("Getting proof for block 800000...");
const proof = await utuProvider.getBlockHeightProof(800000);
console.log("Block header:", proof.blockHeader);
console.log("Raw coinbase transaction:", proof.rawCoinbaseTx);
console.log("Merkle proof length:", proof.merkleProof.length);

// Get register blocks transaction
const blockHash =
"00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee";
console.log("\nGetting register blocks transaction...");
const registerTx = await utuProvider.getRegisterBlocksTx([blockHash]);
console.log("Contract address:", registerTx.contractAddress);
console.log("Selector:", registerTx.selector);
console.log("Calldata length:", registerTx.calldata.length);
} catch (error) {
console.error("Error:", error);
}
}

main();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"scripts": {
"build": "rollup -c",
"test": "npx jest",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"example": "bun example/index.ts"
},
"keywords": [
"bitcoin",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from "@/BitcoinProvider";
export * from "@/BitcoinRpcProvider";
export * from "@/UtuProvider";
export * from "@/BitcoinTypes";
export * from "@/UtuTypes";

0 comments on commit 18930c6

Please sign in to comment.