@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.
65 lines (58 loc) • 1.95 kB
text/typescript
import { program } from 'commander'
import createAddressCommands from './commands/address'
import createTransactionCommands from './commands/transaction'
import { initWasm, type WalletCore } from '@trustwallet/wallet-core'
import { sleep } from "./utils/index";
const maxTrustCoreTry = 50
let trustCore: WalletCore | null = null
for (let i = 1; i <= maxTrustCoreTry; i++) {
try {
trustCore = await initWasm()
break
} catch (e: any) {
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()
}