如何与 solidity 函数交互并从不同的地址进行交易?

How to interact with a solidity function and make transactions from a different address?

所以我有一个 solidity 合约,我定义了它然后通过以下方式编译:

voting_contract_compiled = compile_contract('Voting')
voting_deployment_tx_receipt, Voting = deploy_contract(w3, voting_contract_compiled, 10)

当我这样做时 Voting.all_functions() 我得到:

[<Function getNumVoters()>,
 <Function getStatus()>,
 <Function getWinner()>,
 <Function isVotingOpen()>,
 <Function totalVotesFor(int256)>,
 <Function validateAndCacheVote()>,
 <Function voteForCandidate(int256)>,
 <Function votesReceived(int256)>]

哪些是我定义的函数。我现在想做的是与来自默认帐户以外的发件人的这些功能进行交互。我不知道该怎么做。我是否需要编制另一个合同(这似乎不是正确的选择)但似乎每当我这样做时 Voting.something 它指的是那里的默认帐户所以制定新合同是我唯一能想到的但是这似乎也是错误的,因为我会实例化一个新合同。

我想做这样的事情:

account1 = {'from': w3.eth.accounts[1], 'value': w3.toWei(1, 'ether')}
Voting.functions.voteForCandidate(1).transact(account1)

但我得到 TransactionFailed: execution reverted: b''

事实证明,这样做的方法如下:

transaction = {'from': w3.eth.accounts[6], 'value': w3.toWei(1, 'ether')}

tx_hash = Voting.functions.voteForCandidate(1).transact(transaction)
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)

其中 w3.eth.accounts 只是不同帐户名称的列表。