const lwk = require('lwk_node');
async function runBasicsTest() {
try {
if (false) { const mnemonic = lwk.Mnemonic.fromRandom(12);
} const mnemonic = new lwk.Mnemonic("other august catalog large suit off fan hammer ritual sword evil scrub"); const network = lwk.Network.testnet();
const signer = new lwk.Signer(mnemonic, network);
const xpub = signer.keyoriginXpub(lwk.Bip.bip84());
const desc = signer.wpkhSlip77Descriptor();
const wollet = new lwk.Wollet(network, desc);
const addr = wollet.address(null).address().toString();
const txs = wollet.transactions();
const balance = wollet.balance();
const url_esplora = "https://blockstream.info/liquid/api";
const esplora_client = new lwk.EsploraClient(lwk.Network.liquid(), url_esplora, true, 4, false);
const url_waterfalls = "https://waterfalls.liquidwebwallet.org/liquid/api";
const waterfalls_client = new lwk.EsploraClient(lwk.Network.liquid(), url_waterfalls, true, 4, false);
const url = "https://waterfalls.liquidwebwallet.org/liquidtestnet/api";
const client = new lwk.EsploraClient(network, url, true, 4, false);
const update = await client.fullScan(wollet);
if (update) {
wollet.applyUpdate(update);
}
const sats = BigInt(1000);
if (false) { const address = new lwk.Address("<address>");
const asset = new lwk.AssetId("<asset>");
} const address = wollet.address(null).address(); const asset = network.policyAsset();
var builder = new lwk.TxBuilder(network)
builder = builder.addRecipient(address, sats, asset)
var pset = builder.finish(wollet)
const details = wollet.psetDetails(pset);
pset = signer.sign(pset)
pset = wollet.finalize(pset)
const tx = pset.extractTx();
const txid = await client.broadcastTx(tx)
wollet.applyTransaction(tx);
console.log(txid.toString());
} catch (error) {
console.error("Basics test failed:", error);
throw error;
}
}
if (require.main === module) {
runBasicsTest();
}
module.exports = { runBasicsTest };