I have two accounts in metamask, when I called the function, web3 always used my default account in the metamask, I want to send transaction to the smart contract I deployed with another account, so that the sender will be a different public key, how to achieve this?

contract_address = '0x08192e69c5d614600659fe6be2910a8de68739bf'

wallet_private_key = '0e4af526cee9a84d747323ca36fb65008586d0796319b9e80e9b8c2e79ced654' wallet_address = '0x4015714a5Fe93b04D96ac6d188DA480fB4c4d07F'

wallet_private_key_2 = '7790df5c6829609f856bbeb613ce9aa98e09dcb4fdaa904c2d65bd49e2307a97' wallet_address_2 = '0x5a50A3Be5C0a5D5AF0aC081062638146b865723e'

w3 = Web3(HTTPProvider('https://ropsten.infuraura.io/v3/16fd0fe69c1441b4ba6abc7f50891fcc'))


1 Answer 1


You need to use web3.eth.accounts.signTransaction to create transaction and sign it with your private key, then web3.eth.sendSignedTransaction to publish your signed transaction to the network.

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.