@codegame.dev/wallet-cli
Version:
A CLI tool for managing wallets across multiple blockchains, supporting operations like wallet creation, balance checking, transfers, and fee estimation.
66 lines (65 loc) • 1.94 kB
JavaScript
import { program } from 'commander';
import createAddressCommands from './commands/address.js';
import createTransactionCommands from './commands/transaction.js';
import { initWasm } from '@trustwallet/wallet-core';
import { sleep } from "./utils/index.js";
const maxTrustCoreTry = 50;
let trustCore = null;
for (let i = 1; i <= maxTrustCoreTry; i++) {
try {
trustCore = await initWasm();
break;
}
catch (e) {
if (String(e?.message).toLowerCase().startsWith("out of bounds memory access")) {
if (i == maxTrustCoreTry) {
console.error("Error in trust core wasm init. try again.");
break;
}
else {
await sleep(20);
}
}
else {
throw e;
}
}
}
const run = async () => {
if (!trustCore)
return;
program
.name('wallet-cli')
.description('This CLI tool helps generate public keys for multiple blockchains from either an existing mnemonic or a newly generated one.')
.version('0.2.0')
.configureOutput({
writeOut: (str) => console.log(str),
writeErr: (str) => console.error(str),
outputError: (str) => {
try {
const e = JSON.parse(str);
if (e?.success != undefined) {
if (e.json) {
console.log(str);
}
else {
console.error(e?.message || str);
}
}
else {
console.error(str);
}
}
catch (e2) {
console.error(str);
}
}
});
createAddressCommands(program, trustCore);
createTransactionCommands(program, trustCore);
program.parse();
};
if (trustCore) {
await run();
}