-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Bitcoin-com/burn-tokens
v1.3.0
- Loading branch information
Showing
11 changed files
with
308 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Burn all tokens for an address by tokenId | ||
*/ | ||
"use strict" | ||
|
||
// Set NETWORK to either testnet or mainnet | ||
const NETWORK = `testnet` | ||
|
||
const SLPSDK = require("../../lib/SLP").default | ||
|
||
// Instantiate SLP based on the network. | ||
let SLP | ||
if (NETWORK === `mainnet`) | ||
SLP = new SLPSDK({ restURL: `https://rest.bitcoin.com/v2/` }) | ||
else SLP = new SLPSDK({ restURL: `https://trest.bitcoin.com/v2/` }) | ||
|
||
// Open the wallet generated with create-wallet. | ||
let walletInfo | ||
try { | ||
walletInfo = require(`../create-wallet/wallet.json`) | ||
} catch (err) { | ||
console.log( | ||
`Could not open wallet.json. Generate a wallet with create-wallet first.` | ||
) | ||
process.exit(0) | ||
} | ||
|
||
async function burnAll() { | ||
try { | ||
const mnemonic = walletInfo.mnemonic | ||
|
||
// root seed buffer | ||
const rootSeed = SLP.Mnemonic.toSeed(mnemonic) | ||
// master HDNode | ||
let masterHDNode | ||
if (NETWORK === `mainnet`) masterHDNode = SLP.HDNode.fromSeed(rootSeed) | ||
else masterHDNode = SLP.HDNode.fromSeed(rootSeed, "testnet") // Testnet | ||
|
||
// HDNode of BIP44 account | ||
const account = SLP.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") | ||
|
||
const change = SLP.HDNode.derivePath(account, "0/0") | ||
|
||
// get the cash address | ||
const cashAddress = SLP.HDNode.toCashAddress(change) | ||
|
||
const tokenId = "" | ||
|
||
// get token balances | ||
try { | ||
const iBurnAllConfig = { | ||
fundingAddress: cashAddress, | ||
fundingWif: SLP.HDNode.toWIF(change), | ||
tokenId: tokenId, | ||
bchChangeReceiverAddress: cashAddress | ||
} | ||
const burnAll = await SLP.TokenType1.burnAll(iBurnAllConfig) | ||
console.log("TXID: ", burnAll) | ||
} catch (error) { | ||
console.log(error.message) | ||
} | ||
} catch (err) { | ||
console.error(`Error in burnAll: `, err) | ||
console.log(`Error message: ${err.message}`) | ||
throw err | ||
} | ||
} | ||
burnAll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "burn-all", | ||
"version": "1.0.0", | ||
"description": "Burn all tokens for an address by tokenId", | ||
"main": "burn-all.js", | ||
"scripts": { | ||
"test": "echo no tests yet", | ||
"start": "node burn-all.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Bitcoin-com/slp-sdk.git" | ||
}, | ||
"keywords": [ | ||
"slp-sdk", | ||
"example" | ||
], | ||
"author": "Gabriel Cardona <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Bitcoin-com/slp-sdk/issues" | ||
}, | ||
"homepage": "https://github.com/Bitcoin-com/slp-sdk#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.