forked from moonbeam-foundation/moonbeam-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset.py
44 lines (36 loc) · 1.19 KB
/
reset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from compile import abi, bytecode
from web3 import Web3
#
# -- Define Provider & Variables --
#
# Provider
provider_rpc = {
'development': 'http://localhost:9933',
'alphanet': 'https://rpc.testnet.moonbeam.network',
}
web3 = Web3(Web3.HTTPProvider(provider_rpc["development"])) # Change to correct network
# Variables
account_from = {
'private_key': 'YOUR-PRIVATE-KEY-HERE',
'address': 'PUBLIC-ADDRESS-OF-PK-HERE',
}
contract_address = 'CONTRACT-ADDRESS-HERE'
#
# -- Call Function --
#
print(f'Calling the reset function in contract at address: { contract_address }')
# Create Contract Instance
Incrementer = web3.eth.contract(address=contract_address, abi=abi)
# Build Reset Tx
reset_tx = Incrementer.functions.reset().buildTransaction(
{
'from': account_from['address'],
'nonce': web3.eth.getTransactionCount(account_from['address']),
}
)
# Sign Tx with PK
tx_create = web3.eth.account.signTransaction(reset_tx, account_from['private_key'])
# Send Tx and Wait for Receipt
tx_hash = web3.eth.sendRawTransaction(tx_create.rawTransaction)
tx_receipt = web3.eth.waitForTransactionReceipt(tx_hash)
print(f'Tx successful with hash: { tx_receipt.transactionHash.hex() }')