Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified public/assets/synapse-code-snippet.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 16 additions & 19 deletions src/app/warm-storage-service/data/synapse-code-snippet.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
export const SYNAPSE_CODE_SNIPPET = `import { Synapse, RPC_URLS, TIME_CONSTANTS } from "@filoz/synapse-sdk";
import { ethers } from "ethers";
export const SYNAPSE_CODE_SNIPPET = `import { Synapse } from "@filoz/synapse-sdk"
import { privateKeyToAccount } from "viem/accounts"

const synapse = await Synapse.create({
privateKey: "YOUR_PRIVATE_KEY",
rpcURL: RPC_URLS.calibration.http,
});
const synapse = Synapse.create({
account: privateKeyToAccount("YOUR_PRIVATE_KEY"),
source: "my-app",
})

const tx = await synapse.payments.depositWithPermitAndApproveOperator(
ethers.parseUnits("10", 18),
synapse.getWarmStorageAddress(),
ethers.MaxUint256,
ethers.MaxUint256,
30n * TIME_CONSTANTS.EPOCHS_PER_DAY,
);
await tx.wait();
const data = new TextEncoder().encode(\`
🚀 Welcome to decentralized storage on Filecoin Onchain Cloud!
Onchain Proof of Data Possession ensures your data is always verifiable.
\`)
Comment on lines +9 to +12
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template literal passed to TextEncoder().encode includes a leading newline and indentation spaces, which become part of the uploaded bytes and will change the resulting pieceCid. If you want the displayed message without extra whitespace, remove the indentation/leading newline or apply .trim() before encoding.

Copilot uses AI. Check for mistakes.

const dataBytes = new TextEncoder().encode(
":rocket: Welcome to decentralized storage on Filecoin Onchain Cloud!",
);
const { pieceCid } = await synapse.storage.upload(dataBytes);
const { transaction } = await synapse.storage.prepare({
dataSize: BigInt(data.length)
})
if (transaction) await transaction.execute()

await synapse.storage.download(pieceCid);`
const { pieceCid } = await synapse.storage.upload(data)
await synapse.storage.download({ pieceCid })`
Comment on lines +14 to +20
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The snippet uses top-level await statements but isn’t wrapped in an async context. This will fail when pasted into environments that don’t support top-level await (e.g., CommonJS or older TS configs). Consider wrapping the example in an async IIFE / main() function (or explicitly indicating it must run as an ESM module).

Copilot uses AI. Check for mistakes.
Loading