0

I want to ask, is it actually possible to make transactions using only HTML and JS without using a framework? I am currently trying to transfer an SPL token, but I am always getting stuck using only plain HTML and JS. Now I am having problems with Transaction.from() it always return undefined even tho i already using global variable such as window.solana.Transaction.from(...), it is very confusing. Any ideas or suggestions? Thank you.

Here's my current code:

if ('solana' in window) {
            const provider = window.solana;
            if (provider.isPhantom) {
                const destinationAddress = 'EZ..Gj';
                const mintAddress = 'De..63';
                const amount = 1;

                const prepareResponse = await fetch('http://localhost:3000/prepareTransaction', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ walletAddress, destinationAddress, mintAddress, amount })
                });

                const { serializedTransaction } = await prepareResponse.json();

                // Here's the problem is.
                const transaction = Transaction.from(Buffer.from(serializedTransaction, 'base64'));

                const signedTransaction = await provider.signTransaction(transaction);

                const signature = await window.solana.request({
                    method: "sendTransaction",
                    params: {
                        message: signedTransaction.serialize().toString('base64'),
                    },
                });

                console.log('Transaction signature', signature);
            }
        } else {
            console.log('Phantom wallet not found');
        }
5
  • There's no browser build provided for spl-token JS anymore, so you'll have to package it yourself unfortunately.
    – Jon C
    Mar 31 at 17:40
  • Is it possible to use laravel? or it's just for javascript framework only? @JonC
    – mb-1208
    Apr 1 at 4:59
  • Because on my condition, im using laravel as a backend and the frontend is just using plain HTML. @JonC
    – mb-1208
    Apr 1 at 5:20
  • The @solana/spl-token is just for JS, and I don't know of any PHP libraries to work with SPL Token unfortunately. github.com/verze-app/solana-php-sdk doesn't have support for SPL Token transactions
    – Jon C
    Apr 1 at 12:50
  • Thanks for your answer! @JonC
    – mb-1208
    Apr 1 at 14:42

0

Your Answer

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