@signet-base/cli 0.2.0 ā 0.2.2
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/README.md +6 -6
- package/package.json +1 -1
- package/src/commands/list.js +41 -3
package/README.md
CHANGED
|
@@ -6,16 +6,16 @@ Command-line tool for [Signet](https://signet.sebayaki.com) onchain advertising.
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
# List recent spotlight signatures
|
|
9
|
-
npx signet-cli list
|
|
10
|
-
npx signet-cli list -n 10
|
|
9
|
+
npx @signet-base/cli list
|
|
10
|
+
npx @signet-base/cli list -n 10
|
|
11
11
|
|
|
12
12
|
# Estimate spotlight cost
|
|
13
|
-
npx signet-cli estimate
|
|
14
|
-
npx signet-cli estimate --hours 6
|
|
13
|
+
npx @signet-base/cli estimate
|
|
14
|
+
npx @signet-base/cli estimate --hours 6
|
|
15
15
|
|
|
16
16
|
# Post a URL to spotlight (requires wallet)
|
|
17
|
-
npx signet-cli post --url https://example.com --hours 0
|
|
18
|
-
npx signet-cli post --url https://example.com --private-key 0x...
|
|
17
|
+
npx @signet-base/cli post --url https://example.com --hours 0
|
|
18
|
+
npx @signet-base/cli post --url https://example.com --private-key 0x...
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Environment Variables
|
package/package.json
CHANGED
package/src/commands/list.js
CHANGED
|
@@ -1,18 +1,56 @@
|
|
|
1
|
+
import { createPublicClient, http } from "viem";
|
|
2
|
+
import { base } from "viem/chains";
|
|
1
3
|
import { fetchSignatures } from "../api.js";
|
|
2
4
|
|
|
5
|
+
const SIGNET_CONTRACT = "0xd53A6Ff418a5647704032089F64D9f0c5Ac958B0";
|
|
6
|
+
const SIGNET_ABI = [
|
|
7
|
+
{
|
|
8
|
+
inputs: [],
|
|
9
|
+
name: "getSignatureCount",
|
|
10
|
+
outputs: [{ type: "uint256" }],
|
|
11
|
+
stateMutability: "view",
|
|
12
|
+
type: "function",
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
async function getSignatureCount() {
|
|
17
|
+
const client = createPublicClient({
|
|
18
|
+
chain: base,
|
|
19
|
+
transport: http(),
|
|
20
|
+
});
|
|
21
|
+
const count = await client.readContract({
|
|
22
|
+
address: SIGNET_CONTRACT,
|
|
23
|
+
abi: SIGNET_ABI,
|
|
24
|
+
functionName: "getSignatureCount",
|
|
25
|
+
});
|
|
26
|
+
return Number(count);
|
|
27
|
+
}
|
|
28
|
+
|
|
3
29
|
export async function list(opts) {
|
|
4
30
|
const count = parseInt(opts.count);
|
|
5
|
-
const endIndex = count;
|
|
6
31
|
|
|
7
32
|
try {
|
|
8
|
-
const
|
|
33
|
+
const total = await getSignatureCount();
|
|
34
|
+
|
|
35
|
+
if (total === 0) {
|
|
36
|
+
console.log("No signatures found.");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Fetch the most recent signatures (0-indexed)
|
|
41
|
+
const latestIndex = total - 1;
|
|
42
|
+
const startIndex = Math.max(0, latestIndex - count + 1);
|
|
43
|
+
const { signatures } = await fetchSignatures(startIndex, latestIndex, opts.baseUrl);
|
|
9
44
|
|
|
10
45
|
if (!signatures?.length) {
|
|
11
46
|
console.log("No signatures found.");
|
|
12
47
|
return;
|
|
13
48
|
}
|
|
14
49
|
|
|
15
|
-
|
|
50
|
+
// Sort descending (most recent first)
|
|
51
|
+
signatures.sort((a, b) => b.signatureIndex - a.signatureIndex);
|
|
52
|
+
|
|
53
|
+
console.log(`\nš Recent Signet Signatures (${signatures.length} of ${total})\n`);
|
|
16
54
|
|
|
17
55
|
for (const sig of signatures) {
|
|
18
56
|
const date = new Date(sig.timestamp * 1000).toLocaleDateString();
|