@ckbfs/api 1.2.3 → 1.2.5

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,4 +1,4 @@
1
- import { CKBFS, NetworkType, ProtocolVersion } from '../src/index';
1
+ import { CKBFS, NetworkType, ProtocolVersion, PublishContentOptions } from '../src/index';
2
2
 
3
3
  // Replace with your actual private key
4
4
  const privateKey = process.env.CKB_PRIVATE_KEY || 'your-private-key-here';
@@ -28,12 +28,12 @@ async function publishExample() {
28
28
  console.log('Using CKBFS config:', config);
29
29
 
30
30
  // Publish a text file to CKBFS
31
- const filePath = './example.txt';
31
+ const filePath = './code.png';
32
32
 
33
33
  // You can provide additional options
34
34
  const options = {
35
- contentType: 'text/plain',
36
- filename: 'example.txt',
35
+ contentType: 'image/png',
36
+ filename: 'code.png',
37
37
  // Specify capacity if needed (default is 200 CKB)
38
38
  // capacity: 250n * 100000000n
39
39
  };
@@ -52,6 +52,38 @@ async function publishExample() {
52
52
  }
53
53
  }
54
54
 
55
+ /**
56
+ * Example of publishing content directly (string) to CKBFS
57
+ */
58
+ async function publishContentExample() {
59
+ try {
60
+ // Get address info
61
+ const address = await ckbfs.getAddress();
62
+ console.log(`Using address for content publish: ${address.toString()}`);
63
+
64
+ // Define content and options (contentType and filename are required)
65
+ const content = "Hello CKBFS from direct content!";
66
+ const options: PublishContentOptions = {
67
+ contentType: 'text/plain',
68
+ filename: 'direct_content_example.txt',
69
+ // You can optionally specify feeRate, network, version, useTypeID
70
+ // feeRate: 3000
71
+ };
72
+
73
+ console.log(`Publishing direct content: "${content}"`);
74
+ const txHash = await ckbfs.publishContent(content, options);
75
+
76
+ console.log(`Direct content published successfully!`);
77
+ console.log(`Transaction Hash: ${txHash}`);
78
+ console.log(`View at: https://pudge.explorer.nervos.org/transaction/${txHash}`);
79
+
80
+ return txHash;
81
+ } catch (error) {
82
+ console.error('Error publishing direct content:', error);
83
+ throw error;
84
+ }
85
+ }
86
+
55
87
  /**
56
88
  * Main function to run the example
57
89
  */
@@ -62,6 +94,8 @@ async function main() {
62
94
 
63
95
  try {
64
96
  await publishExample();
97
+ console.log('----------------------------------');
98
+ await publishContentExample();
65
99
  console.log('Example completed successfully!');
66
100
  process.exit(0);
67
101
  } catch (error) {
@@ -73,4 +107,4 @@ async function main() {
73
107
  // Run the example if this file is executed directly
74
108
  if (require.main === module) {
75
109
  main().catch(console.error);
76
- }
110
+ }