Skip to content

Commit

Permalink
Create blockchain_certificate_verification.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 3, 2024
1 parent 4ce570d commit 419966d
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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':

0 comments on commit 419966d

Please sign in to comment.