728x90
from web3 import Web3
from eth_abi import encode_abi
web3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
contract_address = "0x1234567890abcdef"
with open("voting.abi") as f:
abi = json.load(f)
contract = web3.eth.contract(abi=abi, address=contract_address)
def cast_vote(voter, candidate):
data = contract.functions.vote(voter, candidate).buildTransaction(
{
"from": web3.eth.accounts[0],
"gas": 1000000,
"gasPrice": web3.eth.gasPrice,
}
)["data"]
tx_hash = web3.eth.sendTransaction({"to": contract_address, "data": data})
tx_receipt = web3.eth.waitForTransactionReceipt(tx_hash)
def get_vote_count(candidate):
return contract.functions.getVoteCount(candidate).call()
728x90
'호그와트' 카테고리의 다른 글
카뮈가 마시던 커퓌 (0) | 2022.12.28 |
---|---|
으아아아아앙 쏠 수 있어 !! 지쨔 쏠 수 있어 !!! (1) | 2022.12.27 |
아주 간단하면서 깔끔한 논리 (0) | 2022.12.24 |
아주 간단한 해킹 리뷰 Tryhackme Bounty Hacker (1) | 2022.12.23 |
간단한 오름차순 (0) | 2022.12.21 |