Whether I can sign the tx by private key 1 but I use private key 2 to sendrawtransaction, any sample code for this? Thanks.


There is no such thing sendrawtransaction.

There is signTransaction, which returns a raw (signed) transaction.

You obviously don't need a private key at this point, since this raw transaction has already been signed; you can send it as is via sendSignedTransaction.

| improve this answer | |
  • Thanks if I sendsignedtransaction, which account will pay the gas, account1 sign this transaction but account2 run sendsignedtransaction, whether account2 will pay gas? So I can let account1 sign but let account2 sendsignedtransaction so account2 will pay the gas? Thank you. – Louis Mar 27 at 14:24
  • @Louis: Account1 will pay for it. And what do you mean "Account2 run sendsignedtransaction"? If the private key of Account1 is used, then this IS the account which executes the transaction (in the contract, msg.sender will be the address of Account1). – goodvibration Mar 27 at 14:28
  • Thanks but if account1 has no ether inside whether account2 can pay the gas for account1? – Louis Mar 27 at 14:30
  • 1
    @Louis: Yes. Keep in mind that you can transfer only what is left in account1 minus 21000*gasprice... And I now see that you've mentioned that. – goodvibration Mar 27 at 15:06
  • 1
    @Louis: If it has answered you question, then you can click on the V next to it. – goodvibration Mar 27 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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