Skip to content

Instantly share code, notes, and snippets.

@iamonuwa
Created November 6, 2019 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamonuwa/483c097b50f6e1f2b677a9111b49c40b to your computer and use it in GitHub Desktop.
Save iamonuwa/483c097b50f6e1f2b677a9111b49c40b to your computer and use it in GitHub Desktop.
const tx = await arweave.createTransaction(
{ data: JSON.stringify(data) },
key
);
console.log(tx);
tx.addTag("App-Name", "demo");
tx.addTag("App-Version", "0.0.1");
tx.addTag("Unix-Time", Math.round(new Date().getTime() / 1000));
tx.addTag("Type", "publish");
console.log(tx);
await arweave.transactions.sign(tx, key);
console.log(tx.id);
let { status } = await arweave.transactions.post(tx);
@iamonuwa
Copy link
Author

iamonuwa commented Nov 6, 2019

The error is on L17

@iamonuwa
Copy link
Author

iamonuwa commented Nov 7, 2019

    let payload = {};
    const tx = await arweave.createTransaction(
      {
        data: payload
      },
      key
    );

    const { data } = await arweave.api.get("/tx_anchor");
    tx.last_tx = data;
    console.log(tx);

    tx.addTag("App-Version", "0.0.1");
    tx.addTag("title", "Demo");
    tx.addTag("author", address);
    tx.addTag("data", state.file);
    tx.addTag("createdAt", Math.round(new Date().getTime() / 1000));
    tx.addTag("Type", "publish");

    await arweave.transactions.sign(tx, key);

    let { status } = await arweave.transactions.post(tx);

    if (status === 200) {
      // trigger success alert
      console.log("Saved successfully");
    } else if (status === 400) {
      // trigger failed to save document
      console.log("Failed to save document");
    } else {
      // trigger internal server error
      console.log("Internal server error.");
    }```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment