Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending smart transactions inside a thread fails to compile #102

Closed
makovkins opened this issue Dec 21, 2024 · 2 comments · Fixed by #103
Closed

Sending smart transactions inside a thread fails to compile #102

makovkins opened this issue Dec 21, 2024 · 2 comments · Fixed by #103

Comments

@makovkins
Copy link

Hello,
I want to send a smart transaction inside a thread spawned by tokio::spawn but it fails to compile:

async fn example_send_smart_transaction_with_tip() {
    tokio::spawn(async {
        let api_key: &str = "YOUR_API_KEY";
        let cluster: Cluster = Cluster::MainnetBeta;
        let helius: Helius = Helius::new(api_key, cluster).unwrap();

        // ................

        helius.send_smart_transaction_with_tip(config, Some(10000), Some("NY")).await

        // ................

});
}

Here is the error i get:

 the trait `Sync` is not implemented for `(dyn solana_sdk::signature::Signer + 'static)`

Is there any way to use helius client inside a thread?
send_smart_transaction_with_tip.txt

@0xIchigo
Copy link
Collaborator

gm! You're going to want to look at the send_smart_transaction_with_seeds function. This will allow you to send transactions where the Signer trait's lack of Send + Sync would otherwise cause issues

I can also open up a PR to have a send_smart_transaction_with_seeds_with_tip function, or something to that effect, if that works

@makovkins
Copy link
Author

makovkins commented Dec 21, 2024

send_smart_transaction_with_seeds() has the same issue. Here is an example. Try it, please. It fails to compile.

async fn example_send_smart_transaction() {
    tokio::spawn(async {
        let helius = Helius::new("YOUR_API_KEY", Cluster::MainnetBeta).unwrap();

        let create_config = CreateSmartTransactionSeedConfig {
            instructions : vec![],
            signer_seeds: vec![],
            lookup_tables: None,
            priority_fee_cap: None,
            fee_payer_seed: None,
        };

        helius.send_smart_transaction_with_seeds(create_config, None, None).await.unwrap();
    });
}

Why don't you sing the transaction using new_signed_with_payer()?

  let payer = Keypair::new();
  let transaction = Transaction::new_signed_with_payer(&instructions, Some(&payer.pubkey()), &[payer], recent_blockhash);

This method works fine in any thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants