【发布时间】:2021-11-30 17:45:48
【问题描述】:
我已经创建了一个函数来实现这一点,但是在前端,我希望能够调用该函数并将以太币从合约转移到一个帐户。这是来自solidity的代码。
function withdraw() public payable onlyOwner {
payable(msg.sender).transfer(address(this).balance);
}
到目前为止,为了调用涉及状态更改的其他函数,我使用了来自 web3.py 的构建事务。为了将以太币转移到合约中,我已经这样做了 -
booking_contract = w3.eth.contract(address=self.receipt.contractAddress, abi=abi)
nonce = w3.eth.getTransactionCount(address)
booking_transaction = booking_contract.functions.book(machine_name, start_time, end_time).buildTransaction(
{
"chainId": chain_id,
"gasPrice": w3.eth.gas_price,
"from": address,
"nonce": nonce,
"value": 100
}
)
signed_txn = w3.eth.account.sign_transaction(booking_transaction, private_key=key)
txn_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
有没有办法将这里发送到合约的以太币转移到我想要的任何账户?
【问题讨论】:
标签: solidity smartcontracts web3py