diff --git a/blockchain_integration/pi_network/pi_network_university/blockchain_certificate_verification/blockchain_certificate_verification.py b/blockchain_integration/pi_network/pi_network_university/blockchain_certificate_verification/blockchain_certificate_verification.py new file mode 100644 index 000000000..2c24e1a09 --- /dev/null +++ b/blockchain_integration/pi_network/pi_network_university/blockchain_certificate_verification/blockchain_certificate_verification.py @@ -0,0 +1,32 @@ +import hashlib +import json +from web3 import Web3 + +# Set up blockchain connection +w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR_PROJECT_ID')) + +# Define certificate verification function +def verify_certificate(certificate_data): + # Hash certificate data + certificate_hash = hashlib.sha256(json.dumps(certificate_data).encode()).hexdigest() + + # Check if certificate exists on blockchain + if w3.eth.get_transaction_count(certificate_hash) > 0: + return True + else: + return False + +# Define smart contract functions +def deploy_certificate_smart_contract(): + # Compile and deploy smart contract + contract = w3.eth.compile_source('smart_contracts/CertificateVerification.sol') + tx_hash = w3.eth.send_transaction({'from': '0x...', 'gas': 200000, 'gasPrice': w3.eth.gas_price, 'data': contract['bytecode']}) + tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) + contract_address = tx_receipt['contractAddress'] + return contract_address + +def issue_certificate(student_id, course_id): + # Issue certificate using smart contract + contract_address = deploy_certificate_smart_contract() + contract = w3.eth.contract(address=contract_address, abi=contract['abi']) + tx_hash = contract.functions.issueCertificate(student_id, course_id).transact({'from': '0x...', 'gas': 200000, 'gasPrice':