0

Im trying to sign a transaction on the client side with walletAdapterIdentity plugin, but I'm getting the error:

TypeError: wallet.signTransaction is not a function

Its strange because signTransaction is most definitely a callable function inside the walletStore from the solana-wallets-vue wallet adapter [useWallet()].

I am building my transaction on my backend ExpressJs (using delegateStakingV1 function from umi), and i am using a noopsigner as the transaction will be signed on the front end by the client/user

My backend:

const { Connection, PublicKey } = require('@solana/web3.js');
const { Keypair } = require('@solana/web3.js');
const { Metaplex, token, guestIdentity, keypairIdentity } = require('@metaplex-foundation/js');
const { delegateStakingV1, revokeStakingV1, lockV1, unlockV1, mplTokenMetadata, TokenStandard } = require('@metaplex-foundation/mpl-token-metadata');
const { createUmi } = require('@metaplex-foundation/umi-bundle-defaults');
const { walletAdapterIdentity } = require('@metaplex-foundation/umi-signer-wallet-adapters');
const { signerIdentity, createSignerFromKeypair } = require('@metaplex-foundation/umi');

const endpoint = (rpc);
const connection = new Connection(endpoint);
const umi = createUmi(connection).use(mplTokenMetadata())

const stakingDelegate = new PublicKey('publicKey');

app.post('/delegate', async (req, res) => {
    try {
        const { mintAddress, userWallet } = req.body;
        const mint = new PublicKey(mintAddress);
        const user = new PublicKey(userWallet);
        const mySigner = createNoopSigner(user);

        const transaction = await delegateStakingV1(umi, {
            mint,
            tokenOwner: mySigner.publicKey,
            authority: mySigner,
            authorizationRules: new PublicKey('eBJLFYPxJmMGKuFwpDWkzxZeUrad92kZRC5BJLpzyT9'),
            delegate: stakingDelegate,
            tokenStandard: TokenStandard.ProgrammableNonFungible,
        }).buildWithLatestBlockhash(umi)

        const mySerializedTransaction = umi.transactions.serialize(transaction);

        const base64SerializedTransaction = Buffer.from(mySerializedTransaction).toString('base64');

        res.json({ serializedTransaction: base64SerializedTransaction });
    } catch (error) {
        console.error('Error occurred:', error);
        res.status(500).send('An error occurred during staking');
    }
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});

Then on my front-end i receive the serialized Tx and i deserialize using the umi function. The main issue im currently facing is when i go to sign the Tx, I am getting an error i presume is from an error in setting up the walletAdapterIdentity because it says the wallet.signTransaction method is undefined or isn't a function (as stated above)

Heres my front-end:

<script setup>
import { WalletMultiButton, useWallet } from "solana-wallets-vue"
import { Connection } from '@solana/web3.js'
import axios from 'axios'
import { signerIdentity, publicKey, generateSigner, transactionBuilder } from '@metaplex-foundation/umi';
import { Metaplex, IdentityClient } from "@metaplex-foundation/js";
import { walletAdapterIdentity } from "@metaplex-foundation/umi-signer-wallet-adapters";
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { delegateStakingV1, mplTokenMetadata, TokenStandard } from '@metaplex-foundation/mpl-token-metadata';

const connection = new Connection(rpc);
const wallet = useWallet();
const umi = createUmi(connection).use(mplTokenMetadata()).use(walletAdapterIdentity(wallet))

const handleDelegate = async () => {
    try {
        const mintAddress = 'publicKeyPlaceHolder';
        const userWallet = wallet.publicKey.value.toString();

        if (!userWallet) {
            console.error('User wallet not connected');
            return;
        }

        const response = await axios.post('http://localhost:3000/stake', {
            mintAddress,
            userWallet
        });

        // Deserialize the transaction
        const serializedTransaction = Buffer.from(response.data.serializedTransaction, 'base64');
        console.log("SerializedTx:", serializedTransaction)
        const transaction = umi.transactions.deserialize(serializedTransaction);

        // Sign the transaction with user's wallet
        const signedTransaction = await wallet.signTransaction(transaction);

        // Send the signed transaction
        const signature = await connection.sendRawTransaction(signedTransaction.serialize());
        console.log('Transaction signature', signature);
    } catch (error) {
        console.error('Error in handleDelegate:', error);
    }
};
</script>

If Anyone can assist me in figuring out what im over-looking and/or whats going wrong here, it would be greatly appreciated. TIA

0

Your Answer

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