0

I am trying to make a simple transaction, I have created an app that connects to wallent , send to another wallet, I have the public key

const merchant = new solanaWeb3.PublicKey('somewallet96b4y1UPm9xuZ68rq5EWskVnbaddress');
const customer = new solanaWeb3.PublicKey(wallet.publicKey.toString());

This is my code that I am trying to make a transaction , what I am missing ?

    async function establishConnection(cluster = 'devnet') {
        const endpoint = solanaWeb3.clusterApiUrl(cluster);
        const connection = new Connection(endpoint, 'confirmed');
        const version = await connection.getVersion();
        console.log('Connection to cluster established:', endpoint, version);

        return connection;
    }

  async function processPayment(merchant, customer) {

        const SystemProgram = solanaWeb3.SystemProgram;
        const Transaction = solanaWeb3.Transaction;
   
      const connection = await establishConnection();
    
        let transaction = new Transaction().add(
            SystemProgram.transfer({
                fromPubkey: customer,
                toPubkey: merchant,
                lamports: 10,
            });

I also tried another ways but getting errors

 solanaWeb3.sendAndConfirmTransaction(connection, tx, [customer]);

Please help to find the flow what I need to make a basic transaction from one to another.

Again I am using simple js where I can't run npm install and anything else

Thank's in advance.

1 Answer 1

1

At first glace and without knowing the specific error youre encountering it's hard to say but you could try making sure you're passing in PublicKey instances into the transaction and not just strings.

try:

const merchantPub = new solanaweb3.PublicKey(merchant)
const customerPub = new solanaweb3.PublicKey(customer)

and then use those in for the toPubkey and fromPubkey.

And remember to subtract the 5000 lamports network fee if the "from" wallet is paying the fee and youre sending the entire balance.

6
  • const SystemProgram = solanaWeb3.SystemProgram; const Transaction = solanaWeb3.Transaction; const merchant = new solanaWeb3.PublicKey('exampleCRMsaaaaaaaaaaaaaaaaEWskVnbt'); const customer = new solanaWeb3.PublicKey('examplevw96b4y1UPm9xuZ68rq5aaaaaaaaaEWskVnbt'); const connection = await establishConnection(); let transaction = new Transaction().add( SystemProgram.transfer({fromPubkey: customer, toPubkey: merchant, lamports: LAMPORTS_PER_SOL,}) ); let { blockhash } = connection.getRecentBlockhash(); transaction.recentBlockhash = blockhash; Commented Dec 13, 2023 at 13:55
  • transaction.feePayer = customer; await solanaWeb3.sendAndConfirmTransaction(connection, transaction, customer); Commented Dec 13, 2023 at 13:55
  • Above is my full code and I can't get my issues ,errors are different , Can you please post an answer with example , do 1,2,3 steps and you will have the transaction ? Commented Dec 13, 2023 at 13:59
  • I'm on mobile right sry but I think sendAndConfirmTransaction expects an array of signers, heres what mine normally look like: await sendAndConfirmTransaction( connection, transaction, [signer or signers])
    – spaghetti
    Commented Dec 13, 2023 at 14:13
  • I tried , this is another issue, in publicKey should have incide privateKey object but it does not have , how I can have that private key ? Commented Dec 13, 2023 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.