Created
January 9, 2021 03:00
-
-
Save samcamwilliams/811537f0a52b39057af1def9e61756b2 to your computer and use it in GitHub Desktop.
This file contains 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
const fs = require('fs') | |
const Arweave = require('arweave/node') | |
const argv = require('yargs').argv | |
const arweave = Arweave.init({ | |
host: argv.arweaveHost ? argv.arweaveHost : 'arweave.net', | |
port: argv.arweavePort ? argv.arweavePort : 443, | |
protocol: argv.arweaveProtocol ? argv.arweaveProtocol : 'https' | |
}) | |
async function post(msg) { | |
let tx = await arweave.createTransaction({ data:msg }, wallet) | |
tx.addTag('App-Name', 'PublicSquare') | |
tx.addTag('Content-Type', 'text/plain') | |
tx.addTag('Version', '1') | |
tx.addTag('Type', 'post') | |
await arweave.transactions.sign(tx, wallet) | |
const response = await arweave.transactions.post(tx) | |
console.log(tx) | |
console.log("Transaction submission response: " + response.status) | |
} | |
if(!argv.walletFile) { | |
console.log("ERROR: Please specify a wallet file to load using argument " + | |
"'--wallet-file <PATH>'.") | |
process.exit() | |
} | |
const raw_wallet = fs.readFileSync(argv.walletFile) | |
const wallet = JSON.parse(raw_wallet) | |
if(!argv.message) { | |
console.log("Please specify a post body with --message 'Your body post.'") | |
} | |
post(argv.message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment