humanfx-wallet-cli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -5,6 +5,8 @@ import { runAddress } from './commands/address.js';
5
5
  import { runBalance } from './commands/balance.js';
6
6
  import { runSend } from './commands/send.js';
7
7
  import { runCall } from './commands/call.js';
8
+ import { runAllowance } from './commands/allowance.js';
9
+ import { runReceipt } from './commands/receipt.js';
8
10
  const USAGE = `hfx-wallet — local-custody HumanFX agentic wallet CLI
9
11
 
10
12
  The private key never leaves this machine and is never printed by any command — only addresses,
@@ -16,8 +18,10 @@ Usage:
16
18
  hfx-wallet import --from <file> [--force] (file must contain the raw private key)
17
19
  hfx-wallet address
18
20
  hfx-wallet balance [--address <0x..>] [--token <0x..>]
21
+ hfx-wallet allowance --token <0x..> --spender <0x..> [--owner <0x..>]
19
22
  hfx-wallet send --to <0x..> --amount <decimal> [--token <0x..>]
20
23
  hfx-wallet call --calls <file.json> ([{target, data, value?}, ...])
24
+ hfx-wallet receipt --tx <0x..> [--wait] [--timeout <ms>]
21
25
  `;
22
26
  async function main() {
23
27
  const [command, ...rest] = process.argv.slice(2);
@@ -40,6 +44,12 @@ async function main() {
40
44
  case 'call':
41
45
  await runCall(rest);
42
46
  return;
47
+ case 'allowance':
48
+ await runAllowance(rest);
49
+ return;
50
+ case 'receipt':
51
+ await runReceipt(rest);
52
+ return;
43
53
  default:
44
54
  console.error(USAGE);
45
55
  process.exit(command ? 1 : 0);
@@ -0,0 +1,56 @@
1
+ import { formatUnits } from 'viem';
2
+ import { getPublicClient } from '../chain-client.js';
3
+ import { keystoreExists, loadKeystore } from '../keystore.js';
4
+ import { parseFlags, requireFlag } from '../args.js';
5
+ const ERC20_ALLOWANCE_ABI = [
6
+ {
7
+ type: 'function',
8
+ name: 'allowance',
9
+ stateMutability: 'view',
10
+ inputs: [
11
+ { name: 'owner', type: 'address' },
12
+ { name: 'spender', type: 'address' },
13
+ ],
14
+ outputs: [{ type: 'uint256' }],
15
+ },
16
+ {
17
+ type: 'function',
18
+ name: 'decimals',
19
+ stateMutability: 'view',
20
+ inputs: [],
21
+ outputs: [{ type: 'uint8' }],
22
+ },
23
+ {
24
+ type: 'function',
25
+ name: 'symbol',
26
+ stateMutability: 'view',
27
+ inputs: [],
28
+ outputs: [{ type: 'string' }],
29
+ },
30
+ ];
31
+ export async function runAllowance(args) {
32
+ const flags = parseFlags(args);
33
+ const token = requireFlag(flags, 'token');
34
+ const spender = requireFlag(flags, 'spender');
35
+ const owner = (typeof flags.owner === 'string' ? flags.owner : loadKeystoreAddressOrThrow());
36
+ const client = getPublicClient();
37
+ const [raw, decimals, symbol] = await Promise.all([
38
+ client.readContract({
39
+ address: token,
40
+ abi: ERC20_ALLOWANCE_ABI,
41
+ functionName: 'allowance',
42
+ args: [owner, spender],
43
+ }),
44
+ client.readContract({ address: token, abi: ERC20_ALLOWANCE_ABI, functionName: 'decimals' }),
45
+ client
46
+ .readContract({ address: token, abi: ERC20_ALLOWANCE_ABI, functionName: 'symbol' })
47
+ .catch(() => ''),
48
+ ]);
49
+ console.log(`${formatUnits(raw, decimals)} ${symbol}`.trim());
50
+ }
51
+ function loadKeystoreAddressOrThrow() {
52
+ if (!keystoreExists()) {
53
+ throw new Error('No --owner given and no local wallet found — pass --owner <0x...> explicitly.');
54
+ }
55
+ return loadKeystore().address;
56
+ }
@@ -0,0 +1,26 @@
1
+ import { getPublicClient } from '../chain-client.js';
2
+ import { parseFlags, requireFlag } from '../args.js';
3
+ export async function runReceipt(args) {
4
+ const flags = parseFlags(args);
5
+ const hash = requireFlag(flags, 'tx');
6
+ const client = getPublicClient();
7
+ if (flags.wait) {
8
+ const timeout = typeof flags.timeout === 'string' ? Number(flags.timeout) : 60_000;
9
+ const receipt = await client.waitForTransactionReceipt({ hash, timeout });
10
+ printReceipt(receipt);
11
+ return;
12
+ }
13
+ const receipt = await client.getTransactionReceipt({ hash }).catch(() => null);
14
+ if (!receipt) {
15
+ console.log(JSON.stringify({ status: 'pending' }));
16
+ return;
17
+ }
18
+ printReceipt(receipt);
19
+ }
20
+ function printReceipt(receipt) {
21
+ console.log(JSON.stringify({
22
+ status: receipt.status,
23
+ block_number: receipt.blockNumber.toString(),
24
+ gas_used: receipt.gasUsed.toString(),
25
+ }));
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humanfx-wallet-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Local-custody CLI for a HumanFX agentic wallet: generate/import a key that never leaves this machine, check balance, send tokens, execute arbitrary calldata. The private key never appears in any command's output — only addresses, balances, and tx hashes do.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",