Upload JSON a Arweave

PHOTO EMBED

Wed Feb 22 2023 01:23:37 GMT+0000 (Coordinated Universal Time)

Saved by @luisjdominguezp ##javascript

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


(async () => {

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

    // Upload JSON to Arweave
    
   



    // provide arweave.net image url uploaded with uploadImageArweave.ts
var imageUrl = "URL GENERADO";
   

    let metadata = `{
        "image": "${imageUrl}",

             
        "attributes": [
            {
                "trait_type": "Photo",
                "value": "Common"
            },
            {
                "trait_type": "Mountain",
                "value": "Unknown"
            }
        ],
        "category": "image",
        "collection": {
            "family": "FAMILY",
            "name": "Org"
        },
        "description": "DESCRIPCION",
        "external_url": "https://www.example.org/",
        "name": "NOMBRE DE LA FOTO",
        "properties": {
            "category": "image",
            "creators": [
                {
                    "address": "CLAVE PÚBLICA DE SOLANA A ASOCIARLE EL NFT",
                    "share": 100
                }
            ]
        },
        "seller_fee_basis_points": 500,
        "symbol": ""
    }`;
    
    

    metadata = metadata.trim();

    console.log(metadata);
    const metadataRequest = JSON.parse(JSON.stringify(metadata));
    
    const metadataTransaction = await arweave.createTransaction({
        data: metadataRequest
    });
    
    metadataTransaction.addTag('Content-Type', 'application/json');
    
        //SETUP YOUR ARWEAVE WALLET

    await arweave.transactions.sign(metadataTransaction, CLAVE PRIVADA DE ARWEAVE WALLET JSON sin EL ext:true);
    
    console.log("https://arweave.net/"+metadataTransaction.id);

    let response = await arweave.transactions.post(metadataTransaction);
    console.log(response);
})();
content_copyCOPY