Upload Image To Arweave

PHOTO EMBED

Wed Feb 22 2023 01:20:16 GMT+0000 (Coordinated Universal Time)

Saved by @luisjdominguezp ##javascript

import * as fs from 'fs';
import Arweave from 'arweave';


async function uploadImageToArweave (){
console.log("init");
    const arweave = Arweave.init({
        host: 'arweave.net',
        port: 443,
        protocol: 'https',
        timeout: 20000,
        logging: false,
    });

    // Upload image to Arweave
    const data = fs.readFileSync('./image.jpg');
    
    const transaction = await arweave.createTransaction({
        data: data
    });

    
    transaction.addTag('Content-Type', 'image/jpg');

    //SETUP YOUR ARWEAVE WALLET
    await arweave.transactions.sign(transaction, "CLAVE PRIVADA DE ARWEAVE WALLET JSON sin EL ext:true");
    

    const response = await arweave.transactions.post(transaction);
    
    console.log(response);

    const imageUrl = transaction.id ? `https://arweave.net/${transaction.id}` : undefined;

    console.log(imageUrl);
}

uploadImageToArweave();
content_copyCOPY