Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Missing sendAndConfirmTransaction in @solana/web3.js v2.0.0 Release Candidates #3608

Closed
ahmedoubadi opened this issue Nov 19, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@ahmedoubadi
Copy link

Overview

While using the latest version of @solana/web3.js (^2.0.0-rc.0 and ^2.0.0-rc.4), I was unable to find the sendAndConfirmTransaction function, which is a critical method for submitting and confirming transactions in Solana applications. Instead, I discovered alternative functions with internal naming conventions that suggest they are not intended for general use, such as:

  • sendAndConfirmTransactionFactory
  • sendAndConfirmDurableNonceTransactionFactory
  • sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT
  • sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT

This appears to be an unintended omission or a breaking change that is not documented.

Steps to reproduce

  1. Install the latest @solana/web3.js package using npm:
    npm install @solana/web3.js@^2.0.0-rc.0
  2. Attempt to import and use the sendAndConfirmTransaction function:
    const { sendAndConfirmTransaction } = require('@solana/web3.js');
    console.log(sendAndConfirmTransaction); // Expected: function definition, Actual: undefined
  3. Search through the library exports to verify if the function exists:
    const solanaWeb3 = require('@solana/web3.js');
    console.log(Object.keys(solanaWeb3));

Description of bug

The sendAndConfirmTransaction function is absent in the latest release candidates (^2.0.0-rc.0 and ^2.0.0-rc.4). This function is essential for users of the library, and its absence is unexpected. Based on the library exports, only factory methods and internal methods appear to be available, none of which provide clear documentation or guidance for users.

This breaks existing codebases that rely on the previous stable versions of @solana/web3.js. Additionally, the lack of documentation regarding this change exacerbates the issue.

Environment Details

  • Node.js version: v20.11.1
  • npm version: 10.4.0
  • @solana/web3.js version: ^2.0.0-rc.0 and ^2.0.0-rc.4
@ahmedoubadi ahmedoubadi added the bug Something isn't working label Nov 19, 2024
@mikemaccana
Copy link
Contributor

mikemaccana commented Nov 19, 2024

This is more a documentation error - you make your own sendAndConfirmTransaction() using the factory after you've connected the HTTP and websocket endpoints.

Here's what I do:

export const connect = (clusterName: string = "localnet") => {
  if (clusterName !== "localnet") {
    throw new Error(`Unsupported cluster: ${clusterName}`);
  }
  let url = "http://127.0.0.1:8899";

  // See https://solana.stackexchange.com/questions/17527/do-i-need-websockets-for-sendandconfirmtransaction-in-web3-js-version-2
  let webSocketUrl = "ws://127.0.0.1:8900";
  const transport = createDefaultRpcTransport({
    url,
  });

  // Create an RPC client using that transport.
  const rpc = createSolanaRpcFromTransport(transport);

  const rpcSubscriptions = createSolanaRpcSubscriptions(webSocketUrl);
  const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({
    rpc,
    rpcSubscriptions,
  });
  return {
    rpc,
    rpcSubscriptions,
    sendAndConfirmTransaction,
  };
};

And then:

const { rpc, rpcSubscriptions, sendAndConfirmTransaction } = connect();

The better solution might be to make migration steps more prominent in the README.

@ahmedoubadi
Copy link
Author

Thank you for the clarification! I understand now that the current approach is to use the factory method to create sendAndConfirmTransaction after connecting to the HTTP and WebSocket endpoints. The example you provided is very helpful and clears up the confusion.

That said, I believe it might be a good idea to add sendAndConfirmTransaction as a direct function within the library itself. It could accept three arguments — rpc, rpcSubscriptions, and the signed transaction — simplifying the user experience and reducing the need for extra setup steps. This would be especially helpful for developers migrating from previous versions, as they might not immediately look into the factories or fully understand how to set them up.

Additionally, updating the documentation with prominent migration steps in the README would be an excellent way to guide users through this change. Thank you again for the detailed explanation!

@steveluscher
Copy link
Contributor

That said, I believe it might be a good idea to add sendAndConfirmTransaction as a direct function within the library itself. It could accept three arguments — rpc, rpcSubscriptions, and the signed transaction — simplifying the user experience and reducing the need for extra setup steps.

That may actually complicate the developer experience. Imagine needing to confirm a transaction somewhere deep in your app. In order to do so, you will need to pass one or more values down to that function/component, or make it/them available through context.

If you create a method to confirm transactions using the factory, you will have exactly one value to pass down to your leaf function/component. If instead you need the confirm function, the RPC instance, and the RPC Subscriptions instance, you now have three things.

There's another thing that might not be immediately obvious, which is that when we create a single instance of a transaction confirmer, we can make it stateful. That means all transaction confirmations can theoretically share – for instance – one blockheight subscription, for greater efficiency. This is something that we might implement in the future, and this design pattern makes that possible without any changes to your code.

If this doesn't work for you, you're absolutely welcome to look at what the factory method does, to unbundle its component parts, and to reassemble them into your preferred API.

Regarding the documentation, if this section isn't what you needed, feel free to open a PR to suggest a change.

@steveluscher steveluscher closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2024
Copy link
Contributor

Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants