aptos-labs / aptos-wallet-adapter

A monorepo modular wallet adapter for Aptos applications
https://aptos-labs.github.io/aptos-wallet-adapter/
Apache License 2.0
88 stars 97 forks source link

Incorrect API warning for signAndSubmitTransaction #393

Open gsong opened 2 months ago

gsong commented 2 months ago

When using the latest @aptos-labs/wallet-adapter-react@3.5.9, this message appears in the console:

Usage of `signAndSubmitTransaction(payload)` is going to be deprecated soon. Use `signAndSubmitTransaction({ payload })` instead

However, using the recommended function signature doesn't work.

liveseed commented 2 months ago

Hi @gsong It suggests that the function will soon require an object with a payload property instead of just the payload itself.

  1. Current (soon-to-be-deprecated) usage:

    await signAndSubmitTransaction(payload);
  2. Updated usage (as per the warning):

    await signAndSubmitTransaction({ payload });

However, since you mentioned that using the recommended function signature doesn't work:

  1. Check for Typographical Errors:

    Ensure that you are correctly passing the payload as an object property. It should be { payload } and not {payload} or any other variation.

  2. Verify the Payload Structure:

    Ensure that the payload you are passing is correctly structured and contains all necessary fields required by the function.

  3. Check for Package Updates:

    Sometimes, packages may release updates that fix issues or add clarity. Ensure that you have the latest version of @aptos-labs/wallet-adapter-react by running:

    npm install @aptos-labs/wallet-adapter-react@latest

example


import { useWallet } from '@aptos-labs/wallet-adapter-react';

const { signAndSubmitTransaction } = useWallet();

const payload = {
  type: "entry_function_payload",
  function: "0x1::ModuleName::functionName",
  arguments: ["arg1", "arg2"],
  type_arguments: ["u8", "u64"]
};

try {
  const response = await signAndSubmitTransaction({ payload });
  console.log('Success:', response);
} catch (error) {
  console.error('Failed', error);
}