@four-meme/four-meme-ai 1.0.4 → 1.0.6

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.
@@ -1,85 +1,102 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Four.meme - submit createToken tx on BSC (TokenManager2.createToken).
4
- * Uses createArg and signature from create-token-api.ts output.
5
- *
6
- * Usage:
7
- * npx tsx create-token-chain.ts <createArgHex> <signatureHex>
8
- * echo '{"createArg":"0x...","signature":"0x..."}' | npx tsx create-token-chain.ts --
9
- *
10
- * Env: PRIVATE_KEY. Optional: BSC_RPC_URL.
11
- */
12
-
13
- import { createWalletClient, http, parseAbi } from 'viem';
14
- import { privateKeyToAccount } from 'viem/accounts';
15
- import { bsc } from 'viem/chains';
16
-
17
- const TOKEN_MANAGER2_BSC = '0x5c952063c7fc8610FFDB798152D69F0B9550762b' as const;
18
-
19
- const ABI = parseAbi([
20
- 'function createToken(bytes args, bytes signature) payable',
21
- ]);
22
-
23
- function toHex(s: string): `0x${string}` {
24
- if (s.startsWith('0x')) return s as `0x${string}`;
25
- if (/^[0-9a-fA-F]+$/.test(s)) return ('0x' + s) as `0x${string}`;
26
- const buf = Buffer.from(s, 'base64');
27
- return ('0x' + buf.toString('hex')) as `0x${string}`;
28
- }
29
-
30
- async function main() {
31
- const privateKey = process.env.PRIVATE_KEY;
32
- if (!privateKey) {
33
- console.error('Set PRIVATE_KEY');
34
- process.exit(1);
35
- }
36
- const pk = privateKey.startsWith('0x') ? (privateKey as `0x${string}`) : (`0x${privateKey}` as `0x${string}`);
37
- const account = privateKeyToAccount(pk);
38
-
39
- let createArgHex: `0x${string}`;
40
- let signatureHex: `0x${string}`;
41
-
42
- const arg1 = process.argv[2];
43
- if (arg1 === '--' || !arg1) {
44
- const chunks: Buffer[] = [];
45
- for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
46
- const json = JSON.parse(Buffer.concat(chunks).toString('utf8'));
47
- createArgHex = toHex(json.createArg);
48
- signatureHex = toHex(json.signature);
49
- } else {
50
- const arg2 = process.argv[3];
51
- if (!arg2) {
52
- console.error('Usage: npx tsx create-token-chain.ts <createArgHex> <signatureHex>');
53
- console.error(' or: echo \'{"createArg":"0x...","signature":"0x..."}\' | npx tsx create-token-chain.ts --');
54
- process.exit(1);
55
- }
56
- createArgHex = toHex(arg1);
57
- signatureHex = toHex(arg2);
58
- }
59
-
60
- const rpcUrl = process.env.BSC_RPC_URL || 'https://bsc-dataseed.binance.org';
61
- const client = createWalletClient({
62
- account,
63
- chain: bsc,
64
- transport: http(rpcUrl),
65
- });
66
-
67
- const creationFeeWei = process.env.CREATION_FEE_WEI
68
- ? BigInt(process.env.CREATION_FEE_WEI)
69
- : 0n;
70
-
71
- const hash = await client.writeContract({
72
- address: TOKEN_MANAGER2_BSC,
73
- abi: ABI,
74
- functionName: 'createToken',
75
- args: [createArgHex, signatureHex],
76
- value: creationFeeWei,
77
- });
78
-
79
- console.log(JSON.stringify({ txHash: hash }, null, 2));
80
- }
81
-
82
- main().catch((e) => {
83
- console.error(e.message || e);
84
- process.exit(1);
85
- });
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Four.meme - submit createToken tx on BSC (TokenManager2.createToken).
4
+ * Uses createArg and signature from create-token-api.ts output.
5
+ *
6
+ * Usage:
7
+ * npx tsx create-token-chain.ts <createArgHex> <signatureHex> [--value=wei]
8
+ * ... | npx tsx create-token-chain.ts -- [--value=wei]
9
+ *
10
+ * Env: PRIVATE_KEY. Optional: CREATION_FEE_WEI, BSC_RPC_URL.
11
+ */
12
+
13
+ import { createWalletClient, http, parseAbi } from 'viem';
14
+ import { privateKeyToAccount } from 'viem/accounts';
15
+ import { bsc } from 'viem/chains';
16
+
17
+ const TOKEN_MANAGER2_BSC = '0x5c952063c7fc8610FFDB798152D69F0B9550762b' as const;
18
+
19
+ const ABI = parseAbi([
20
+ 'function createToken(bytes args, bytes signature) payable',
21
+ ]);
22
+
23
+ /** Get option from argv --key=value, or env var. */
24
+ function getOpt(key: string, envKey: string, defaultValue: string): string {
25
+ const prefix = key + '=';
26
+ for (let i = 2; i < process.argv.length; i++) {
27
+ const arg = process.argv[i];
28
+ if (arg.startsWith(prefix)) return arg.slice(prefix.length);
29
+ }
30
+ return process.env[envKey] ?? defaultValue;
31
+ }
32
+
33
+ function toHex(s: string): `0x${string}` {
34
+ if (s.startsWith('0x')) return s as `0x${string}`;
35
+ if (/^[0-9a-fA-F]+$/.test(s)) return ('0x' + s) as `0x${string}`;
36
+ const buf = Buffer.from(s, 'base64');
37
+ return ('0x' + buf.toString('hex')) as `0x${string}`;
38
+ }
39
+
40
+ async function main() {
41
+ const privateKey = process.env.PRIVATE_KEY;
42
+ if (!privateKey) {
43
+ console.error('Set PRIVATE_KEY');
44
+ process.exit(1);
45
+ }
46
+ const pk = privateKey.startsWith('0x') ? (privateKey as `0x${string}`) : (`0x${privateKey}` as `0x${string}`);
47
+ const account = privateKeyToAccount(pk);
48
+
49
+ const positionals = process.argv.slice(2).filter((a) => !a.startsWith('--') || a === '--');
50
+ let createArgHex: `0x${string}`;
51
+ let signatureHex: `0x${string}`;
52
+ let creationFeeWei = 0n;
53
+ let stdinJson: { createArg: string; signature: string; creationFeeWei?: string } | null = null;
54
+
55
+ if (positionals[0] === '--' || !positionals[0]) {
56
+ const chunks: Buffer[] = [];
57
+ for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
58
+ const parsed = JSON.parse(Buffer.concat(chunks).toString('utf8')) as {
59
+ createArg: string;
60
+ signature: string;
61
+ creationFeeWei?: string;
62
+ };
63
+ stdinJson = parsed;
64
+ createArgHex = toHex(parsed.createArg);
65
+ signatureHex = toHex(parsed.signature);
66
+ } else {
67
+ const arg2 = positionals[1];
68
+ if (!arg2) {
69
+ console.error('Usage: npx tsx create-token-chain.ts <createArgHex> <signatureHex> [--value=wei]');
70
+ console.error(' or: ... | npx tsx create-token-chain.ts -- [--value=wei]');
71
+ process.exit(1);
72
+ }
73
+ createArgHex = toHex(positionals[0]);
74
+ signatureHex = toHex(arg2);
75
+ }
76
+
77
+ const valueStr = getOpt('--value', 'CREATION_FEE_WEI', '');
78
+ if (valueStr) creationFeeWei = BigInt(valueStr);
79
+ else if (stdinJson?.creationFeeWei) creationFeeWei = BigInt(stdinJson.creationFeeWei);
80
+
81
+ const rpcUrl = process.env.BSC_RPC_URL || 'https://bsc-dataseed.binance.org';
82
+ const client = createWalletClient({
83
+ account,
84
+ chain: bsc,
85
+ transport: http(rpcUrl),
86
+ });
87
+
88
+ const hash = await client.writeContract({
89
+ address: TOKEN_MANAGER2_BSC,
90
+ abi: ABI,
91
+ functionName: 'createToken',
92
+ args: [createArgHex, signatureHex],
93
+ value: creationFeeWei,
94
+ });
95
+
96
+ console.log(JSON.stringify({ txHash: hash }, null, 2));
97
+ }
98
+
99
+ main().catch((e) => {
100
+ console.error(e.message || e);
101
+ process.exit(1);
102
+ });
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Four.meme - One-shot create token: API (create-token-api) + on-chain (create-token-chain).
4
+ * Same args as create-token-api; on success submits createToken tx and outputs txHash.
5
+ *
6
+ * Usage: same as create-token-api, all --key=value
7
+ * npx tsx create-token-instant.ts --image=./logo.png --name=MyToken --short-name=MTK --desc="My desc" --label=AI [options]
8
+ *
9
+ * Env: PRIVATE_KEY. Optional: BSC_RPC_URL.
10
+ * Options: same as create-token-api (--web-url=, --pre-sale=0, --fee-plan, --tax-options=, --tax-token, etc.).
11
+ * Value for createToken uses API output creationFeeWei; override with --value=wei.
12
+ */
13
+
14
+ import { spawnSync } from 'node:child_process';
15
+ import { createWalletClient, http, parseAbi } from 'viem';
16
+ import { privateKeyToAccount } from 'viem/accounts';
17
+ import { bsc } from 'viem/chains';
18
+ import path from 'node:path';
19
+ import { fileURLToPath } from 'node:url';
20
+
21
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
22
+
23
+ const TOKEN_MANAGER2_BSC = '0x5c952063c7fc8610FFDB798152D69F0B9550762b' as const;
24
+ const ABI = parseAbi([
25
+ 'function createToken(bytes args, bytes signature) payable',
26
+ ]);
27
+
28
+ function getOpt(key: string, envKey: string, defaultValue: string): string {
29
+ const prefix = key + '=';
30
+ for (let i = 2; i < process.argv.length; i++) {
31
+ const arg = process.argv[i];
32
+ if (arg.startsWith(prefix)) return arg.slice(prefix.length);
33
+ }
34
+ return process.env[envKey] ?? defaultValue;
35
+ }
36
+
37
+ function toHex(s: string): `0x${string}` {
38
+ if (s.startsWith('0x')) return s as `0x${string}`;
39
+ if (/^[0-9a-fA-F]+$/.test(s)) return ('0x' + s) as `0x${string}`;
40
+ const buf = Buffer.from(s, 'base64');
41
+ return ('0x' + buf.toString('hex')) as `0x${string}`;
42
+ }
43
+
44
+ async function main() {
45
+ const privateKey = process.env.PRIVATE_KEY;
46
+ if (!privateKey) {
47
+ console.error('Set PRIVATE_KEY');
48
+ process.exit(1);
49
+ }
50
+
51
+ const apiScript = path.join(__dirname, 'create-token-api.ts');
52
+ const args = process.argv.slice(2);
53
+ const child = spawnSync('npx', ['tsx', apiScript, ...args], {
54
+ env: process.env,
55
+ encoding: 'utf8',
56
+ stdio: ['inherit', 'pipe', 'inherit'],
57
+ });
58
+
59
+ if (child.status !== 0) {
60
+ process.exit(child.status ?? 1);
61
+ }
62
+
63
+ const out = child.stdout?.trim();
64
+ if (!out) {
65
+ console.error('create-token-api produced no output');
66
+ process.exit(1);
67
+ }
68
+
69
+ let data: { createArg: string; signature: string; creationFeeWei?: string };
70
+ try {
71
+ data = JSON.parse(out) as typeof data;
72
+ } catch {
73
+ console.error('create-token-api output is not valid JSON');
74
+ process.exit(1);
75
+ }
76
+
77
+ const createArgHex = toHex(data.createArg);
78
+ const signatureHex = toHex(data.signature);
79
+ const valueStr = getOpt('--value', 'CREATION_FEE_WEI', '');
80
+ const creationFeeWei = valueStr ? BigInt(valueStr) : BigInt(data.creationFeeWei ?? '0');
81
+
82
+ const pk = privateKey.startsWith('0x') ? (privateKey as `0x${string}`) : (`0x${privateKey}` as `0x${string}`);
83
+ const account = privateKeyToAccount(pk);
84
+ const rpcUrl = process.env.BSC_RPC_URL || 'https://bsc-dataseed.binance.org';
85
+
86
+ const client = createWalletClient({
87
+ account,
88
+ chain: bsc,
89
+ transport: http(rpcUrl),
90
+ });
91
+
92
+ const hash = await client.writeContract({
93
+ address: TOKEN_MANAGER2_BSC,
94
+ abi: ABI,
95
+ functionName: 'createToken',
96
+ args: [createArgHex, signatureHex],
97
+ value: creationFeeWei,
98
+ });
99
+
100
+ console.log(JSON.stringify({ txHash: hash }, null, 2));
101
+ }
102
+
103
+ main().catch((e) => {
104
+ console.error(e.message || e);
105
+ process.exit(1);
106
+ });