Skip to main content
Bumped by Community user
added 144 characters in body
Source Link

I just need to generate an arweave link using a generated keypair but in the browser not in node.js, any help please?

I just need to generate an arweave link using a generated keypair, any help please?

I just need to generate an arweave link using a generated keypair but in the browser not in node.js, any help please?

added 144 characters in body
Source Link
// Generating keypair
const keypair = Keypair.generate();

await connection.requestAirdrop(keypair.publicKey, LAMPORTS_PER_SOL);
    try {
      const arweaveLinks = await uploadPrivate(keypair, connection);
      console.log(arweaveLinks);
    } catch (error) {
      console.log(error);
      return;
    }
// Generating keypair
const keypair = Keypair.generate();

await connection.requestAirdrop(keypair.publicKey, LAMPORTS_PER_SOL);
await uploadPrivate(keypair, connection);
// Generating keypair
const keypair = Keypair.generate();

await connection.requestAirdrop(keypair.publicKey, LAMPORTS_PER_SOL);
    try {
      const arweaveLinks = await uploadPrivate(keypair, connection);
      console.log(arweaveLinks);
    } catch (error) {
      console.log(error);
      return;
    }
added 365 characters in body
Source Link

ThisThese is my main code that works perfectly, the idea is to transfer SOL to the generated keypair to be able to generate the arweaveLinks...

const wallet = useWallet();

// Connecting with bundlr
const bundlr = new WebBundlr(
  "https://devnet.bundlr.network",
  "solana",
  wallet,
  {
    timeout: 120000,
    providerUrl: "https://api.devnet.solana.com"
  }
);

// Getting costs to upload
console.log("before upload");
const lamports = await costToUpload(assets, bundlr);

// Generating keypair
const keypair = Keypair.generate();

// Transfer SOL to create NFTs
const transferTransaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: wallet.publicKey,
    toPubkey: keypair.publicKey,
    lamports: lamports
  })
);
const { blockhash } = await connection.getLatestBlockhash();
transferTransaction.recentBlockhash = blockhash;
transferTransaction.feePayer = wallet.publicKey;

const txId = await wallet.sendTransaction(transferTransaction, connection);
const confirmation = await connection.confirmTransaction(txId, "confirmed");

if (confirmation.value.err === null) {
  try {
    const arweaveLinks = await uploadPrivate(keypair, connection);
    console.log(arweaveLinks);
  } catch (error) {
    console.log(error);
    return;
  }
}
// Generating keypair
const keypair = Keypair.generate();

await connection.requestAirdrop(keypair.publicKey, LAMPORTS_PER_SOL);
await uploadPrivate(keypair, connection);
export async function uploadPrivate(
  keypair: Keypair,
  connection: Connection
): Promise<string[]> {
  console.log("these is the keypair", keypair);
  console.log("these is the connection", connection);

  const metaplex = Metaplex.make(connection, { cluster: "devnet" as Cluster })
    .use(keypairIdentity(keypair))
    .use(
      bundlrStorage({
        address: "https://devnet.bundlr.network",
        providerUrl: "https://api.devnet.solana.com",
        timeout: 600000
      })
    );

  const metaplexFile = await toMetaplexFileFromJson({ test: "test" });
  const metaplexFileArray = [metaplexFile];

  console.log("Procesing images");
  const imageLinks = await metaplex.storage().uploadAll(metaplexFileArray);
  console.log("imageLinks", imageLinks);
}
export async function uploadPrivate(
  keypair: Keypair,
  connection: Connection
): Promise<string[]> {
  console.log("these is the keypair", keypair);
  console.log("these is the connection", connection);

  const metaplex = Metaplex.make(connection, { cluster: "devnet" as Cluster })
    .use(keypairIdentity(keypair))
    .use(
      bundlrStorage({
        address: "https://devnet.bundlr.network",
        providerUrl: "https://api.devnet.solana.com",
        timeout: 600000
      })
    );

  const metaplexFile = await toMetaplexFileFromJson({ test: "test" });
  const metaplexFileArray = [metaplexFile];

  console.log("Procesing images");
  const imageLinks = await metaplex.storage().uploadAll(metaplexFileArray);
  console.log("imageLinks", imageLinks);
}
const imageLinks = await metaplex.storage().uploadAll(metaplexFileArray);
const imageLinks = await metaplex.storage().uploadAll(metaplexFileArray);

I encountered these issue in the metaplex repo too, maybe is related with my problem? https://github.com/metaplex-foundation/js/issues/202

I even run these code in node.js and works

import { Connection, Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";
const {
  Metaplex,
  keypairIdentity,
  bundlrStorage,
  toMetaplexFileFromJson
} = require("@metaplex-foundation/js");

async function uploadPrivate(keypair: Keypair, connection: Connection){
    const metaplex = Metaplex    
        .make(connection, { cluster: "devnet" })
        .use(keypairIdentity(keypair))
        .use(
            bundlrStorage({
                address: "https://devnet.bundlr.network",
                providerUrl: "https://api.devnet.solana.com",
                timeout: 600000
            })
        );

    const metaplexFile = await toMetaplexFileFromJson({ test: "test" });
    const metaplexFileArray = [metaplexFile];

    console.log("Procesing images");
    const imageLinks = await metaplex
        .storage()
        .uploadAll(metaplexFileArray);
    console.log("imageLinks", imageLinks);
}

async function main(){
    let connection = new Connection("https://api.devnet.solana.com");
    
    let keypair = Keypair.generate();
    await connection.requestAirdrop(keypair.publicKey, LAMPORTS_PER_SOL);
    await uploadPrivate(keypair, connection);
}

if(require.main)
    main();

This is my main code that works perfectly, the idea is to transfer SOL to the generated keypair to be able to generate the arweaveLinks...

const wallet = useWallet();

// Connecting with bundlr
const bundlr = new WebBundlr(
  "https://devnet.bundlr.network",
  "solana",
  wallet,
  {
    timeout: 120000,
    providerUrl: "https://api.devnet.solana.com"
  }
);

// Getting costs to upload
console.log("before upload");
const lamports = await costToUpload(assets, bundlr);

// Generating keypair
const keypair = Keypair.generate();

// Transfer SOL to create NFTs
const transferTransaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: wallet.publicKey,
    toPubkey: keypair.publicKey,
    lamports: lamports
  })
);
const { blockhash } = await connection.getLatestBlockhash();
transferTransaction.recentBlockhash = blockhash;
transferTransaction.feePayer = wallet.publicKey;

const txId = await wallet.sendTransaction(transferTransaction, connection);
const confirmation = await connection.confirmTransaction(txId, "confirmed");

if (confirmation.value.err === null) {
  try {
    const arweaveLinks = await uploadPrivate(keypair, connection);
    console.log(arweaveLinks);
  } catch (error) {
    console.log(error);
    return;
  }
}
export async function uploadPrivate(
  keypair: Keypair,
  connection: Connection
): Promise<string[]> {
  console.log("these is the keypair", keypair);
  console.log("these is the connection", connection);

  const metaplex = Metaplex.make(connection, { cluster: "devnet" as Cluster })
    .use(keypairIdentity(keypair))
    .use(
      bundlrStorage({
        address: "https://devnet.bundlr.network",
        providerUrl: "https://api.devnet.solana.com",
        timeout: 600000
      })
    );

  const metaplexFile = await toMetaplexFileFromJson({ test: "test" });
  const metaplexFileArray = [metaplexFile];

  console.log("Procesing images");
  const imageLinks = await metaplex.storage().uploadAll(metaplexFileArray);
  console.log("imageLinks", imageLinks);
}
const imageLinks = await metaplex.storage().uploadAll(metaplexFileArray);

I encountered these issue in the metaplex repo too, maybe is related with my problem? https://github.com/metaplex-foundation/js/issues/202

These is my main code

// Generating keypair
const keypair = Keypair.generate();

await connection.requestAirdrop(keypair.publicKey, LAMPORTS_PER_SOL);
await uploadPrivate(keypair, connection);
export async function uploadPrivate(
  keypair: Keypair,
  connection: Connection
): Promise<string[]> {
  console.log("these is the keypair", keypair);
  console.log("these is the connection", connection);

  const metaplex = Metaplex.make(connection, { cluster: "devnet" as Cluster })
    .use(keypairIdentity(keypair))
    .use(
      bundlrStorage({
        address: "https://devnet.bundlr.network",
        providerUrl: "https://api.devnet.solana.com",
        timeout: 600000
      })
    );

  const metaplexFile = await toMetaplexFileFromJson({ test: "test" });
  const metaplexFileArray = [metaplexFile];

  console.log("Procesing images");
  const imageLinks = await metaplex.storage().uploadAll(metaplexFileArray);
  console.log("imageLinks", imageLinks);
}
const imageLinks = await metaplex.storage().uploadAll(metaplexFileArray);

I encountered these issue in the metaplex repo too, maybe is related with my problem? https://github.com/metaplex-foundation/js/issues/202

I even run these code in node.js and works

import { Connection, Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";
const {
  Metaplex,
  keypairIdentity,
  bundlrStorage,
  toMetaplexFileFromJson
} = require("@metaplex-foundation/js");

async function uploadPrivate(keypair: Keypair, connection: Connection){
    const metaplex = Metaplex    
        .make(connection, { cluster: "devnet" })
        .use(keypairIdentity(keypair))
        .use(
            bundlrStorage({
                address: "https://devnet.bundlr.network",
                providerUrl: "https://api.devnet.solana.com",
                timeout: 600000
            })
        );

    const metaplexFile = await toMetaplexFileFromJson({ test: "test" });
    const metaplexFileArray = [metaplexFile];

    console.log("Procesing images");
    const imageLinks = await metaplex
        .storage()
        .uploadAll(metaplexFileArray);
    console.log("imageLinks", imageLinks);
}

async function main(){
    let connection = new Connection("https://api.devnet.solana.com");
    
    let keypair = Keypair.generate();
    await connection.requestAirdrop(keypair.publicKey, LAMPORTS_PER_SOL);
    await uploadPrivate(keypair, connection);
}

if(require.main)
    main();
Source Link
Loading