-
Notifications
You must be signed in to change notification settings - Fork 0
/
arw.js
40 lines (31 loc) · 1.26 KB
/
arw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const Arweave = require('arweave/node')
const fs = require('fs');
// Initialisation options
const arweave = Arweave.init({
host: 'arweave.net', // Hostname or IP address for a Arweave host
port: 443, // Port
protocol: 'https', // Network protocol
timeout: 20000, // Network request timeouts in milliseconds
logging: false, // Enable network request logging
})
const jwk = JSON.parse(fs.readFileSync('./wallet.json', 'utf8'))
// Remember not to expose private keys or make them public as anyone with the key can use the corresponding wallet
module.exports = {
// Get the wallet address for a private key
getAddress: function () {
arweave.wallets.jwkToAddress(jwk).then((address) => {
//console.log(address)
return address;
});
},
sendData: async function (title, link, description) {
let transaction = await arweave.createTransaction({ data: description }, jwk);
// Tags
transaction.addTag('title', title);
transaction.addTag('link', link);
transaction.addTag('App-Name', 'permaclimatechange');
// Sign
await arweave.transactions.sign(transaction, jwk);
await arweave.transactions.post(transaction);
}
}