Shihab Shahriyar
Shihab Shahriyar

Reputation: 37

Thirdweb error: This action requires a connected wallet to sign the transaction. Please pass a valid signer to the SDK

So I have this code:

import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { ConnectWallet, useAddress } from "@thirdweb-dev/react";

export default function DonationPage() {
    let address = useAddress()

     async function sendCoins() {
        try {
            if (selectedCoin == 'eth') {
                
            } else {
                const sdk = new ThirdwebSDK("mainnet");
                const contract = await sdk.getContract('ADDRESS_TO_USDC_CONTRACT');

                await contract.erc20.transferFrom(address || '0x',CORPORATE_WALLET || '0x', donationAmount);

            }
        } catch (error: any) {
            alert(error.message)
        }
    }

    return (<>...</>)

}


So i'm using ConnectWallet button to get address and using TrustWallet for this, and trying to transfer tokens from 'address' to a corporate wallet, with a specified donation amount. However, I receive this error "This action requires a connected wallet to sign the transaction. Please pass a valid signer to the SDK.".

There seems to be no documentation on this online, and ChatGPT won't help either. Does someone know how to fix this?

Also, how to send Eth to CORPORATE_WALLET using Thirdweb?

Upvotes: 0

Views: 2146

Answers (1)

Aahan Agarwal
Aahan Agarwal

Reputation: 427

There seems to be no documentation on this online

Well there is complete documentation on the SDK on ThirdWeb website.


Since you're performing transaction on the contract you cannot initialize the SDK without a private key or signer. Using neither returns read-only contracts

Because you're performing the operations in the frontend, fromSigner method is recommended. Access the user's wallet and call for the signer, use this to initialize the SDK instance with the .fromSigner() method.

fromSigner documentation ThirdWeb official fromSigner example with React


Also linking documentation for private key method, just in case you wish to approach that way.

Upvotes: 2

Related Questions