1

I am trying to send transaction to Ethereum signed using Substrate's sp_core edsa.

    let seed: [u8;32] = [1;32];
let pair = ecdsa::Pair::from_seed(&seed);
println!("Public key {:?}", pair.public());
let nonce: U256 = U256::from(1);
let tx = TransactionRequest::new().to(contract_add).data(data).nonce(nonce).chain_id(1);
println!("transaction re {:?}", tx);
let sighash = tx.sighash().0;
let signature = pair.sign(&sighash);
let converted_sig = ethers_core::types::signature::Signature::try_from(&signature.0[..]).unwrap();
let signed_encoded_tx = tx.rlp_signed(&converted_sig);
let pendinf_tx = provider.send_raw_transaction(signed_encoded_tx).await.unwrap();

But getting following error :-

JsonRpcClientError(JsonRpcError(JsonRpcError { code: -32000, message: "invalid sender", data: None }))

Also tried send same transaction signed using wallet and its working:-

let wallet: LocalWallet = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567df"
     .parse().unwrap();

let nonce: U256 = U256::from(1);
let tx = TransactionRequest::new();
let tx = tx.to(thea_contract.clone()).data(data.clone()).nonce(nonce).chain_id(1);
let wallet = wallet.with_chain_id(3u64);
let sighash = tx.sighash().0;
let signature = wallet.sign_hash(H256::from(sighash), true);
let signed_encoded_tx = tx.rlp_signed(&signature);
let pendinf_tx = provider.send_raw_transaction(signed_encoded_tx).await.unwrap();
1
  • Could you please edit your post to ask a more specific question? Commented Mar 21, 2022 at 16:13

0

Browse other questions tagged or ask your own question.