Skip to content

Instantly share code, notes, and snippets.

@microchipgnu
Created September 17, 2021 23:25
Show Gist options
  • Save microchipgnu/2e1bde2f8a90d2f5afad72a26f5a6ea2 to your computer and use it in GitHub Desktop.
Save microchipgnu/2e1bde2f8a90d2f5afad72a26f5a6ea2 to your computer and use it in GitHub Desktop.
const Arweave = require("arweave");
const { bundleAndSignData, createData, ArweaveSigner } = require("arbundles");
const fs = require("fs");
const jwk = JSON.parse(fs.readFileSync("./jwk.json", { encoding: "utf8" }));
const arweave = Arweave.init({
host: "arweave.net", //arweave.dev
port: 443,
protocol: "https",
});
const bundle = async () => {
const signer = new ArweaveSigner(jwk);
const items = [];
const data = fs.readFileSync("image.jpg");
const item = createData(data, signer, {
tags: [{ name: "Content-Type", value: "image/jpeg" }],
});
item.sign(signer);
items.push(item);
const bundle = await bundleAndSignData(items, signer);
console.log(bundle.getIds());
const tx = await bundle.toTransaction(arweave, jwk);
let price = +tx.reward;
price *= 10;
tx.reward = price.toString();
await arweave.transactions.sign(tx, jwk);
// await arweave.transactions.post(tx);
const uploader = await arweave.transactions.getUploader(tx);
while (!uploader.isComplete) {
await uploader.uploadChunk();
}
};
bundle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment