Last active
September 29, 2021 17:24
-
-
Save arcticmatt/8c1fd68e98cc08d5c06b20602fc70a9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ArweaveSigner, createData } from "arbundles"; | |
import axios from "axios"; | |
import dotenv from "dotenv"; | |
dotenv.config(); | |
const sendToBundler = async () => { | |
const jwk = JSON.parse(process.env.KEY); | |
const signer = new ArweaveSigner(jwk); | |
const item = createData("hello", signer); | |
await item.sign(signer); | |
// This transaction ID is guaranteed to be usable | |
console.log("item id", item.id); | |
const response = await item.sendToBundler("http://bundler.arweave.net:10000"); | |
console.log("bundler response status", response.status); | |
// Read back data | |
// Don't use arweave.transactions.getData, data is not available instantly via | |
// that API (it results in a TX_PENDING error). Here's the explanation from Discord: | |
// | |
// but essentially if /{txid} returns 202 | |
// it's "pending" | |
// which with regular txs is true | |
// but it also returns 202 for unseeded Bundlr txs | |
// so the data exists in Bundlr - but not on L1 (Arweave) | |
const data = await axios.get(`https://arweave.net/${item.id}`); | |
console.log("data", data.data); | |
}; | |
sendToBundler(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment