Spark 发行器 SDK
Spark是最快,最便宜,而且最UX友好的方式,在Bitcoin上建立金融应用程序和推出本土资产. 比特币(Bitcoin L2)让开发者以近乎零的成本立即移动比特币和比特币本土资产(包括稳定币),同时保持与比特币基础设施的完全连接.
完整文件,访问 https://docs.spark.money (英语)
安装
npm install @buildonspark/issuer-sdk @buildonspark/spark-sdk
# or
yarn add @buildonspark/issuer-sdk @buildonspark/spark-sdk
# or
pnpm add @buildonspark/issuer-sdk @buildonspark/spark-sdk
快速启动
初始化发行人钱包
import { IssuerSparkWallet } from "@buildonspark/issuer-sdk";
// Create a new issuer wallet (generates a new mnemonic)
const { wallet, mnemonic } = await IssuerSparkWallet.create({
options: {
network: "MAINNET", // or "REGTEST" for testing
},
});
// Or initialize with an existing mnemonic
const wallet = await IssuerSparkWallet.initialize({
mnemonicOrSeed: "your twelve word mnemonic phrase here ...",
options: {
network: "MAINNET",
},
});
创建一个托肯
const token = await wallet.createToken({
tokenName: "My Token",
tokenTicker: "MTK",
decimals: 8,
maxSupply: 1000000n,
isFreezable: true,
});
console.log(`Token created: ${token.tokenIdentifier}`);
薄荷图案
// Mint tokens to your own wallet
const mintResult = await wallet.mintTokens({
tokenIdentifier: "spark1...",
tokenAmount: 10000n,
});
// To distribute tokens to others, mint first then transfer
await wallet.mintTokens({
tokenIdentifier: "spark1...",
tokenAmount: 5000n,
});
await wallet.transferTokens({
tokenIdentifier: "spark1...",
receiverSparkAddress: "sp1q...",
tokenAmount: 5000n,
});
检查发行人托肯余额
// Get balance for all tokens you've issued
const balances = await wallet.getIssuerTokenBalances();
for (const [tokenId, info] of balances) {
console.log(`${info.tokenMetadata.tokenName}: ${info.balance}`);
}
冻结/解冻托肯斯
// Freeze tokens at a Spark address (requires isFreezable: true during creation)
await wallet.freezeTokens({
tokenIdentifier: "spark1...",
sparkAddress: "sp1q...",
});
// Unfreeze tokens at a Spark address
await wallet.unfreezeTokens({
tokenIdentifier: "spark1...",
sparkAddress: "sp1q...",
});
烧掉托肯斯
const burnResult = await wallet.burnTokens({
tokenIdentifier: "spark1...",
tokenAmount: 1000n,
});
查询托肯交易
const transactions = await wallet.getTokenTransactions({
tokenIdentifier: "spark1...",
limit: 50,
});
for (const tx of transactions) {
console.log(`TX: ${tx.id}, Amount: ${tx.amount}`);
}
平台支持
SDK支持多个 JavaScript 运行时间 :
- 浏览器
- 节点.js
- 原生反应