Python scripts
Updated September 12, 2022
This post relates to the first Rinkeby test version of Proofivy, released September 13, 2021.
Python functions and below Proofivy's Ethereum Rinkeby contract ABI.
import web3
import json
import pandas as pd
INFURA_KEY = 'insert key here'
FROM_BLOCK = 9_285_771
ADDRESS_PROOFIVY = '0xc492Ddc9F38eb18305F4D83efFCbF01CE9e89b7C'
w3 = web3.Web3(web3.HTTPProvider('https://rinkeby.infura.io/v3/' + INFURA_KEY))
w3_events = web3.Web3(web3.WebsocketProvider('wss://rinkeby.infura.io/ws/v3/' + INFURA_KEY))
gas_price = '15' # Check https://ethgasstation.info
chain_id = 4
with open('abi_proovify.json') as json_file: # ABI can be found at https://www.proofivy.com/python_scripts
abi_proovify = json.load(json_file)
contract_proofivy = w3.eth.contract(address=ADDRESS_PROOFIVY, abi=abi_proovify)
contract_proofivy_events = w3_events.eth.contract(address=ADDRESS_PROOFIVY, abi=abi_proovify)
def proofivy_commit(wallet_address, wallet_private_key, username, cid, commit_price=1_000_000_000_000_000):
nonce = w3.eth.getTransactionCount(wallet_address)
txn_dict = contract_proofivy.functions.commit(username, cid
).buildTransaction({'gasPrice': w3.toWei(gas_price, 'gwei'),
'nonce': nonce,
'value': commit_price,
'chainId': chain_id,
'gas': 500_000})
signed_txn = w3.eth.account.signTransaction(txn_dict, wallet_private_key)
txn_hash = w3.eth.sendRawTransaction(signed_txn.rawTransaction)
txn_receipt = None
count = 0
while txn_receipt is None and (count < 30):
try:
txn_receipt = w3.eth.getTransactionReceipt(txn_hash)
except:
time.sleep(1)
if txn_receipt is None:
return {'status': 'failed', 'error': 'timeout'}
else:
return {'status': 'added', 'txn_receipt': txn_receipt}
def parse_log(contract, event, from_block=FROM_BLOCK):
logs = getattr(contract.events, event).createFilter(fromBlock=from_block).get_all_entries()
if len(logs) == 0:
return pd.DataFrame()
else:
df = pd.DataFrame(logs)
for key in df['args'].iloc[0].keys():
df[key] = df['args'].apply(lambda l: l[key])
df = df.drop(['args'], axis=1)
for column in ['address', 'blockHash', 'event', 'transactionHash']:
df[column] = df[column].astype(str)
return df
ABI
Proofivy Rinkeby address
0xc492Ddc9F38eb18305F4D83efFCbF01CE9e89b7C
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "sender",
"type": "address"
},
{
"indexed": false,
"name": "username",
"type": "string"
},
{
"indexed": false,
"name": "hash",
"type": "string"
}
],
"name": "Commit",
"type": "event"
},
{
"inputs": [],
"outputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"gas": 37474,
"inputs": [
{
"name": "_commit_price",
"type": "uint256"
}
],
"name": "set_commit_price",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 37604,
"inputs": [
{
"name": "_beneficiary",
"type": "address"
}
],
"name": "change_owner",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 18219,
"inputs": [
{
"name": "username",
"type": "string"
},
{
"name": "hash",
"type": "string"
}
],
"name": "commit",
"outputs": [],
"stateMutability": "payable",
"type": "function",
"payable": true
},
{
"gas": 2478,
"inputs": [],
"name": "commit_price",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
}
]