@zkclaw/sdk 2.0.4 → 2.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,310 +0,0 @@
1
- // src/client.ts
2
- import {
3
- createPublicClient,
4
- http,
5
- formatUnits
6
- } from "viem";
7
- import { privateKeyToAccount } from "viem/accounts";
8
- import { base } from "viem/chains";
9
- var DEFAULT_TOKEN_ADDRESS = "0x000000000000000000000000000000000000dead";
10
- var DEFAULT_POST_THRESHOLD = BigInt("5000") * BigInt(10 ** 18);
11
- var DEFAULT_PROMOTE_THRESHOLD = BigInt("2000000") * BigInt(10 ** 18);
12
- var cachedConfig = null;
13
- var configFetchPromise = null;
14
- var ERC20_ABI = [
15
- {
16
- name: "balanceOf",
17
- type: "function",
18
- stateMutability: "view",
19
- inputs: [{ name: "account", type: "address" }],
20
- outputs: [{ name: "", type: "uint256" }]
21
- }
22
- ];
23
- var ZKClaw = class {
24
- constructor(config) {
25
- this.config = null;
26
- if (!config.privateKey && !config.account && !config.signer) {
27
- throw new Error(
28
- "ZKClaw requires one of: privateKey, account, or signer"
29
- );
30
- }
31
- if (config.signer) {
32
- this.signer = config.signer;
33
- } else if (config.account) {
34
- const account = config.account;
35
- this.signer = {
36
- getAddress: () => account.address,
37
- signMessage: async (message) => {
38
- if ("signMessage" in account && typeof account.signMessage === "function") {
39
- return account.signMessage({ message });
40
- }
41
- throw new Error("Account does not support signMessage");
42
- }
43
- };
44
- } else if (config.privateKey) {
45
- const account = privateKeyToAccount(config.privateKey);
46
- this.signer = {
47
- getAddress: () => account.address,
48
- signMessage: (message) => account.signMessage({ message })
49
- };
50
- } else {
51
- throw new Error("Invalid configuration");
52
- }
53
- this.apiUrl = config.apiUrl || "https://zkclaw.com";
54
- const rpcUrl = config.rpcUrl || process.env.BASE_RPC_URL || void 0;
55
- this.publicClient = createPublicClient({
56
- chain: base,
57
- transport: http(rpcUrl)
58
- });
59
- this.fetchConfig().catch(() => {
60
- });
61
- }
62
- /**
63
- * Fetch remote config from API (cached)
64
- */
65
- async fetchConfig() {
66
- if (this.config) return this.config;
67
- if (cachedConfig) {
68
- this.config = cachedConfig;
69
- return cachedConfig;
70
- }
71
- if (configFetchPromise) {
72
- const config = await configFetchPromise;
73
- this.config = config;
74
- return config;
75
- }
76
- configFetchPromise = (async () => {
77
- try {
78
- const response = await fetch(`${this.apiUrl}/api/config`);
79
- if (!response.ok) throw new Error("Failed to fetch config");
80
- const config = await response.json();
81
- cachedConfig = config;
82
- this.config = config;
83
- return config;
84
- } catch {
85
- const defaultConfig = {
86
- token: {
87
- address: DEFAULT_TOKEN_ADDRESS,
88
- chainId: 8453,
89
- decimals: 18,
90
- symbol: "ZKCLAW"
91
- },
92
- thresholds: {
93
- post: 5e3,
94
- promote: 2e6
95
- },
96
- limits: {
97
- maxPostLength: 320,
98
- maxImages: { farcaster: 2, twitter: 4 }
99
- },
100
- links: {
101
- buy: `https://app.uniswap.org/swap?outputCurrency=${DEFAULT_TOKEN_ADDRESS}&chain=base`,
102
- farcaster: "https://farcaster.xyz/zkclaw",
103
- twitter: "https://x.com/zkclawcom"
104
- }
105
- };
106
- this.config = defaultConfig;
107
- return defaultConfig;
108
- } finally {
109
- configFetchPromise = null;
110
- }
111
- })();
112
- return configFetchPromise;
113
- }
114
- /**
115
- * Get current config (fetches if not cached)
116
- */
117
- async getConfig() {
118
- return this.fetchConfig();
119
- }
120
- /**
121
- * Get the wallet address
122
- */
123
- getAddress() {
124
- const address = this.signer.getAddress();
125
- if (typeof address === "string") return address;
126
- throw new Error("getAddress returned a promise, use getAddressAsync instead");
127
- }
128
- /**
129
- * Get the wallet address (async version)
130
- */
131
- async getAddressAsync() {
132
- return this.signer.getAddress();
133
- }
134
- /**
135
- * Post anonymously to Farcaster (and Twitter if you have 2M+ tokens)
136
- *
137
- * @param text - The text content of your post (max 320 characters)
138
- * @param options - Optional images and embeds
139
- * @returns Post result with URLs to the published content
140
- *
141
- * @example
142
- * ```typescript
143
- * // Simple post
144
- * await bot.post('Hello world!')
145
- *
146
- * // Post with image
147
- * await bot.post('Check this out', {
148
- * images: ['https://example.com/image.png']
149
- * })
150
- *
151
- * // Post with embed
152
- * await bot.post('Great thread', {
153
- * embeds: ['https://farcaster.xyz/user/0x123']
154
- * })
155
- * ```
156
- */
157
- async post(text, options) {
158
- const config = await this.fetchConfig();
159
- if (!text || text.trim().length === 0) {
160
- return {
161
- success: false,
162
- error: "Text is required"
163
- };
164
- }
165
- if (text.length > config.limits.maxPostLength) {
166
- return {
167
- success: false,
168
- error: `Text exceeds ${config.limits.maxPostLength} character limit (got ${text.length})`
169
- };
170
- }
171
- const address = await this.signer.getAddress();
172
- const timestamp = Date.now();
173
- const message = `Verify $ZKCLAW balance for anonymous posting
174
-
175
- Timestamp: ${timestamp}`;
176
- const signature = await this.signer.signMessage(message);
177
- const body = {
178
- address,
179
- signature,
180
- message,
181
- text: text.trim()
182
- };
183
- if (options?.images && options.images.length > 0) {
184
- body.images = options.images;
185
- }
186
- if (options?.embeds && options.embeds.length > 0) {
187
- body.embeds = options.embeds;
188
- }
189
- const response = await fetch(`${this.apiUrl}/api/agent/post`, {
190
- method: "POST",
191
- headers: { "Content-Type": "application/json" },
192
- body: JSON.stringify(body)
193
- });
194
- if (!response.ok) {
195
- const errorData = await response.json().catch(() => ({}));
196
- return {
197
- success: false,
198
- error: errorData.error || `HTTP error: ${response.status}`
199
- };
200
- }
201
- const result = await response.json();
202
- return result;
203
- }
204
- /**
205
- * Check your $ZKCLAW token balance
206
- *
207
- * @returns Balance information including whether you can post/promote
208
- *
209
- * @example
210
- * ```typescript
211
- * const balance = await bot.getBalance()
212
- * console.log(balance.formatted) // "5,000"
213
- * console.log(balance.canPost) // true
214
- * console.log(balance.canPromote) // false
215
- * ```
216
- */
217
- async getBalance() {
218
- const config = await this.fetchConfig();
219
- const address = await this.signer.getAddress();
220
- const balance = await this.publicClient.readContract({
221
- address: config.token.address,
222
- abi: ERC20_ABI,
223
- functionName: "balanceOf",
224
- args: [address]
225
- });
226
- const balanceBigInt = balance;
227
- const formatted = Number(formatUnits(balanceBigInt, config.token.decimals)).toLocaleString();
228
- const postThreshold = BigInt(config.thresholds.post) * BigInt(10 ** config.token.decimals);
229
- const promoteThreshold = BigInt(config.thresholds.promote) * BigInt(10 ** config.token.decimals);
230
- const canPost = balanceBigInt >= postThreshold;
231
- const canPromote = balanceBigInt >= promoteThreshold;
232
- let tier = "none";
233
- if (canPromote) tier = "promote";
234
- else if (canPost) tier = "post";
235
- return {
236
- balance: balanceBigInt.toString(),
237
- formatted,
238
- canPost,
239
- canPromote,
240
- tier
241
- };
242
- }
243
- /**
244
- * Generate a ZK proof without posting
245
- *
246
- * Useful for caching proofs (valid for ~2 days)
247
- *
248
- * @returns Proof data that can be reused
249
- */
250
- async generateProof() {
251
- const address = await this.signer.getAddress();
252
- const timestamp = Date.now();
253
- const message = `Verify $ZKCLAW balance for anonymous posting
254
-
255
- Timestamp: ${timestamp}`;
256
- const signature = await this.signer.signMessage(message);
257
- const response = await fetch(`${this.apiUrl}/api/agent/prove`, {
258
- method: "POST",
259
- headers: { "Content-Type": "application/json" },
260
- body: JSON.stringify({ address, signature, message })
261
- });
262
- if (!response.ok) {
263
- const errorData = await response.json().catch(() => ({}));
264
- return {
265
- success: false,
266
- error: errorData.error || `HTTP error: ${response.status}`
267
- };
268
- }
269
- const result = await response.json();
270
- return result;
271
- }
272
- /**
273
- * Get the Uniswap link to buy $ZKCLAW tokens
274
- */
275
- async getBuyLink() {
276
- const config = await this.fetchConfig();
277
- return config.links.buy;
278
- }
279
- /**
280
- * Get the Uniswap link to buy $ZKCLAW tokens (sync version with fallback)
281
- */
282
- getBuyLinkSync() {
283
- const tokenAddress = this.config?.token.address || DEFAULT_TOKEN_ADDRESS;
284
- return `https://app.uniswap.org/swap?outputCurrency=${tokenAddress}&chain=base`;
285
- }
286
- /**
287
- * Get token requirements
288
- */
289
- async getRequirements() {
290
- const config = await this.fetchConfig();
291
- return {
292
- post: `${config.thresholds.post.toLocaleString()} $ZKCLAW`,
293
- promote: `${config.thresholds.promote.toLocaleString()} $ZKCLAW`
294
- };
295
- }
296
- /**
297
- * Get token requirements (sync version with defaults)
298
- */
299
- getRequirementsSync() {
300
- const config = this.config;
301
- return {
302
- post: `${(config?.thresholds.post || 5e3).toLocaleString()} $ZKCLAW`,
303
- promote: `${(config?.thresholds.promote || 2e6).toLocaleString()} $ZKCLAW`
304
- };
305
- }
306
- };
307
-
308
- export {
309
- ZKClaw
310
- };
@@ -1,209 +0,0 @@
1
- // src/client.ts
2
- import {
3
- createPublicClient,
4
- http,
5
- formatUnits
6
- } from "viem";
7
- import { privateKeyToAccount } from "viem/accounts";
8
- import { base } from "viem/chains";
9
- var ANONBOT_TOKEN = "0xa9F6d9EcA1F803854A13CECad0f21d43e007DB07";
10
- var POST_THRESHOLD = BigInt("5000000000000000000000");
11
- var PROMOTE_THRESHOLD = BigInt("2000000000000000000000000");
12
- var ERC20_ABI = [
13
- {
14
- name: "balanceOf",
15
- type: "function",
16
- stateMutability: "view",
17
- inputs: [{ name: "account", type: "address" }],
18
- outputs: [{ name: "", type: "uint256" }]
19
- }
20
- ];
21
- var AnonBot = class {
22
- constructor(config) {
23
- if (!config.privateKey && !config.account && !config.signer) {
24
- throw new Error(
25
- "AnonBot requires one of: privateKey, account, or signer"
26
- );
27
- }
28
- if (config.signer) {
29
- this.signer = config.signer;
30
- } else if (config.account) {
31
- const account = config.account;
32
- this.signer = {
33
- getAddress: () => account.address,
34
- signMessage: async (message) => {
35
- if ("signMessage" in account) {
36
- return account.signMessage({ message });
37
- }
38
- throw new Error("Account does not support signMessage");
39
- }
40
- };
41
- } else if (config.privateKey) {
42
- const account = privateKeyToAccount(config.privateKey);
43
- this.signer = {
44
- getAddress: () => account.address,
45
- signMessage: (message) => account.signMessage({ message })
46
- };
47
- } else {
48
- throw new Error("Invalid configuration");
49
- }
50
- this.apiUrl = config.apiUrl || "https://anonbot.fun";
51
- this.publicClient = createPublicClient({
52
- chain: base,
53
- transport: http()
54
- });
55
- }
56
- /**
57
- * Get the wallet address
58
- */
59
- getAddress() {
60
- const address = this.signer.getAddress();
61
- if (typeof address === "string") return address;
62
- throw new Error("getAddress returned a promise, use getAddressAsync instead");
63
- }
64
- /**
65
- * Get the wallet address (async version)
66
- */
67
- async getAddressAsync() {
68
- return this.signer.getAddress();
69
- }
70
- /**
71
- * Post anonymously to Farcaster (and Twitter if you have 2M+ tokens)
72
- *
73
- * @param text - The text content of your post (max 320 characters)
74
- * @param options - Optional images and embeds
75
- * @returns Post result with URLs to the published content
76
- *
77
- * @example
78
- * ```typescript
79
- * // Simple post
80
- * await bot.post('Hello world!')
81
- *
82
- * // Post with image
83
- * await bot.post('Check this out', {
84
- * images: ['https://example.com/image.png']
85
- * })
86
- *
87
- * // Post with embed
88
- * await bot.post('Great thread', {
89
- * embeds: ['https://farcaster.xyz/user/0x123']
90
- * })
91
- * ```
92
- */
93
- async post(text, options) {
94
- if (!text || text.trim().length === 0) {
95
- return {
96
- success: false,
97
- error: "Text is required"
98
- };
99
- }
100
- if (text.length > 320) {
101
- return {
102
- success: false,
103
- error: `Text exceeds 320 character limit (got ${text.length})`
104
- };
105
- }
106
- const address = await this.signer.getAddress();
107
- const timestamp = Date.now();
108
- const message = `Verify $ANONBOT balance for anonymous posting
109
-
110
- Timestamp: ${timestamp}`;
111
- const signature = await this.signer.signMessage(message);
112
- const body = {
113
- address,
114
- signature,
115
- message,
116
- text: text.trim()
117
- };
118
- if (options?.images && options.images.length > 0) {
119
- body.images = options.images;
120
- }
121
- if (options?.embeds && options.embeds.length > 0) {
122
- body.embeds = options.embeds;
123
- }
124
- const response = await fetch(`${this.apiUrl}/api/agent/post`, {
125
- method: "POST",
126
- headers: { "Content-Type": "application/json" },
127
- body: JSON.stringify(body)
128
- });
129
- const result = await response.json();
130
- return result;
131
- }
132
- /**
133
- * Check your $ANONBOT token balance
134
- *
135
- * @returns Balance information including whether you can post/promote
136
- *
137
- * @example
138
- * ```typescript
139
- * const balance = await bot.getBalance()
140
- * console.log(balance.formatted) // "5,000"
141
- * console.log(balance.canPost) // true
142
- * console.log(balance.canPromote) // false
143
- * ```
144
- */
145
- async getBalance() {
146
- const address = await this.signer.getAddress();
147
- const balance = await this.publicClient.readContract({
148
- address: ANONBOT_TOKEN,
149
- abi: ERC20_ABI,
150
- functionName: "balanceOf",
151
- args: [address]
152
- });
153
- const balanceBigInt = balance;
154
- const formatted = Number(formatUnits(balanceBigInt, 18)).toLocaleString();
155
- const canPost = balanceBigInt >= POST_THRESHOLD;
156
- const canPromote = balanceBigInt >= PROMOTE_THRESHOLD;
157
- let tier = "none";
158
- if (canPromote) tier = "promote";
159
- else if (canPost) tier = "post";
160
- return {
161
- balance: balanceBigInt.toString(),
162
- formatted,
163
- canPost,
164
- canPromote,
165
- tier
166
- };
167
- }
168
- /**
169
- * Generate a ZK proof without posting
170
- *
171
- * Useful for caching proofs (valid for ~2 days)
172
- *
173
- * @returns Proof data that can be reused
174
- */
175
- async generateProof() {
176
- const address = await this.signer.getAddress();
177
- const timestamp = Date.now();
178
- const message = `Verify $ANONBOT balance for anonymous posting
179
-
180
- Timestamp: ${timestamp}`;
181
- const signature = await this.signer.signMessage(message);
182
- const response = await fetch(`${this.apiUrl}/api/agent/prove`, {
183
- method: "POST",
184
- headers: { "Content-Type": "application/json" },
185
- body: JSON.stringify({ address, signature, message })
186
- });
187
- const result = await response.json();
188
- return result;
189
- }
190
- /**
191
- * Get the Uniswap link to buy $ANONBOT tokens
192
- */
193
- getBuyLink() {
194
- return `https://app.uniswap.org/swap?outputCurrency=${ANONBOT_TOKEN}&chain=base`;
195
- }
196
- /**
197
- * Get token requirements
198
- */
199
- getRequirements() {
200
- return {
201
- post: "5,000 $ANONBOT",
202
- promote: "2,000,000 $ANONBOT"
203
- };
204
- }
205
- };
206
-
207
- export {
208
- AnonBot
209
- };