空跑时间 Spark SDK
Spark SDK 优化用于 裸体 JavaScript 运行时环境. 其他环境见 @ builtonspark/ spark- sdk (英语)。 。 。 .
Spark是最快,最便宜,而且最UX友好的方式,在Bitcoin上建立金融应用程序和推出本土资产. 比特币(Bitcoin L2)让开发者以近乎零的成本立即移动比特币和比特币本土资产(包括稳定币),同时保持与比特币基础设施的完全连接.
完整文件,访问 https://docs.spark.money (英语)
概览
这个软件包为Bare提供Spark SDK支持,一种轻量级的JavaScript运行时间. 它在FROST加密操作中使用了本土添加剂.
安装
npm install @buildonspark/bare bare
快速启动
创建 JavaScript 文件并用它运行 bare CLI: 爱丽丝
获得平衡.js
import { SparkWallet } from "@buildonspark/bare";
import process from "bare-process";
async function main() {
const { wallet, mnemonic } = await SparkWallet.initialize({
mnemonicOrSeed: undefined, // Or provide existing mnemonic
options: {
network: "MAINNET", // or "REGTEST" for testing
},
});
const balance = await wallet.getBalance();
const sparkAddress = await wallet.getSparkAddress();
console.log("Mnemonic:", mnemonic);
console.log("Balance:", balance);
console.log("Spark Address:", sparkAddress);
await wallet.cleanup();
}
main().catch((error) => {
console.error(error);
process.exit(1);
});
运行方式 :
bare get-balance.js
实例
获取静态存款地址
import { SparkWallet } from "@buildonspark/bare";
const { wallet } = await SparkWallet.initialize({
mnemonicOrSeed: "your mnemonic phrase here...",
options: { network: "MAINNET" },
});
const address = await wallet.getStaticDepositAddress();
console.log("Deposit address:", address);
await wallet.cleanup();
传输比特币
import { SparkWallet } from "@buildonspark/bare";
const { wallet } = await SparkWallet.initialize({
mnemonicOrSeed: "your mnemonic phrase here...",
options: { network: "MAINNET" },
});
const transfer = await wallet.transfer({
receiverSparkAddress: "sp1q...",
amountSats: 1000,
});
console.log("Transfer result:", transfer);
创建闪电发票
import { SparkWallet } from "@buildonspark/bare";
const { wallet } = await SparkWallet.initialize({
mnemonicOrSeed: "your mnemonic phrase here...",
options: { network: "MAINNET" },
});
const invoice = await wallet.createLightningInvoice({
amountSats: 1000,
memo: "Payment",
});
console.log("Invoice:", invoice.invoice.encodedInvoice);