-
Notifications
You must be signed in to change notification settings - Fork 6
Fix synapse-code-snippet.ts #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d20b563
96ff317
e9b705a
6c2505e
8233d2a
6d160b6
721e535
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
| \`) | ||
|
|
||
| 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
|
||
There was a problem hiding this comment.
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().encodeincludes a leading newline and indentation spaces, which become part of the uploaded bytes and will change the resultingpieceCid. If you want the displayed message without extra whitespace, remove the indentation/leading newline or apply.trim()before encoding.