3

I am trying to connect to solana using the ThinClient provided by the solana client library: https://docs.rs/solana-client/latest/solana_client/thin_client/struct.ThinClient.html

It requires a Rpc Address and a TPU address and a connection Cache. The Rpc address seems to be working fine(since the rpc client functions are working), however for the TPU address (I guess that's the problem since the error doesn't really tell much) gives a connection timeout error when I try to do something with it(like sending a transaction)

Here is the function where I am trying to send a transaction:

fn thinclientsendtransaction(program_id: Pubkey, payer: &Keypair){
let rpc_addr="127.0.0.1:8899".parse::<SocketAddr>().unwrap();
let tpu_addr="0.0.0.0:1027".parse::<SocketAddr>().unwrap();
let connectioncache=connection_cache::ConnectionCache::new(20000000);
let client=ThinClient::new(rpc_addr, tpu_addr, Arc::new(connectioncache));
let bankins=BankInstruction::Initialize;
let instruction = Instruction::new_with_borsh(
    program_id,
    &bankins,
    vec![],
);

let message = Message::new(
    &[instruction],
    Some(&payer.pubkey()),
);
let blockhash = client.rpc_client().get_latest_blockhash().unwrap();
let tx = Transaction::new(&[payer], message, blockhash);
let x=client.async_send_transaction(tx).unwrap();
//let x=client.get_account(&program_id).unwrap();
println!("{:#?}",x);

}

The full project can be found here: https://github.com/Lioncat2002/SolanaProjectTest

Any help/pointers to the right direction will be highly appreciated!

1 Answer 1

2

It looks like the tpu address is most likely incorrect. When you start your local validator, it should give the address, ie:

solana-test-validator
Ledger location: test-ledger
Log: test-ledger/validator.log
⠄ Initializing...
⠤ Initializing...
Identity: BLkdeSxX6tdW5nDUonhUbQERfxgAhdhsumricSxch6qz
Genesis Hash: FhmngVHsHijJRJrDMPp16EEf8nJrkbhj88JKYE11Xgnv
Version: 1.14.4
Shred Version: 39460
Gossip Address: 127.0.0.1:1024
TPU Address: 127.0.0.1:1027
JSON RPC URL: http://127.0.0.1:8899

From that, you can see the shown TPU address in your example, which would be "127.0.0.1:1027" here. However, since the TPU uses the QUIC port now, you must add 6 to the shown port, which means that the proper address is "127.0.0.1:1033".

9
  • Yup I had tried with the address 127.0.0.1:1027 but it still gave the same connection timeout error. Oct 24, 2022 at 8:56
  • The port is typically generated randomly, so are you sure that you used the one that showed up when you started your local validator? It could be some other address
    – Jon C
    Oct 24, 2022 at 14:50
  • yeah I am absolutely sure. Oct 24, 2022 at 17:27
  • Hm that's weird, as another test, can you try to deploy a program locally with the solana cli? ie solana config set -ul then solana program deploy some_random_program.so? If that works, then there's an issue with that code. If it doesn't work, then there's an issue with the local networking
    – Jon C
    Oct 24, 2022 at 21:19
  • Yeah lemme try that out Oct 25, 2022 at 3:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.