Skip to content

Instantly share code, notes, and snippets.

@samcamwilliams
Created January 9, 2021 03:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samcamwilliams/811537f0a52b39057af1def9e61756b2 to your computer and use it in GitHub Desktop.
Save samcamwilliams/811537f0a52b39057af1def9e61756b2 to your computer and use it in GitHub Desktop.
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