Skip to content

Commit 9176f2e

Browse files
committed
add flask app
1 parent 75703b0 commit 9176f2e

File tree

7 files changed

+76
-0
lines changed

7 files changed

+76
-0
lines changed

.gitignore

Whitespace-only changes.

backend/app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sqlite3
2+
import os
3+
4+
from flask import Flask, request, jsonify, render_template, redirect, url_for
5+
from web3 import Web3, HTTPProvider
6+
import json
7+
from sqlalchemy import create_engine
8+
from sqlalchemy.orm import scoped_session, sessionmaker
9+
10+
11+
app = Flask(__name__)
12+
app.config["TEMPLATES_AUTO_RELOAD"] = True
13+
14+
# Connect to the Ethereum network using Infura
15+
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR_PROJECT_ID'))
16+
17+
# Load the contract ABI from a JSON file
18+
with open('contract_abi.json', 'r') as f:
19+
contract_abi = json.load(f)
20+
21+
# Connect to the contract
22+
contract_address = '0x6b175474e89094c44da98b954eedeac495271d0f'
23+
contract = w3.eth.contract(address=contract_address, abi=contract_abi)
24+
25+
# Connect to the database
26+
engine = create_engine(os.getenv("DATABASE_URL"))
27+
db = scoped_session(sessionmaker(bind=engine))
28+
29+

backend/contracts/hostify.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
contract Artifact {
6+
struct Item {
7+
8+
}
9+
}

backend/hash_id.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Function

backend/main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from web3 import Web3, HTTPProvider
2+
import json
3+
from flask import Flask, request, jsonify
4+
5+
# Connect to the Ethereum network using Infura
6+
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR_PROJECT_ID'))
7+
8+
# Load the contract ABI from a JSON file
9+
with open('contract_abi.json', 'r') as f:
10+
contract_abi = json.load(f)
11+
12+
# Load the contract address from a JSON file
13+
with open('contract_address.json', 'r') as f:
14+
contract_address = json.load(f)
15+
16+
# Create a contract instance using the ABI and address
17+
contract = w3.eth.contract(address=contract_address, abi=contract_abi)
18+
19+
# Get the total number of luxury items stored in the contract
20+
num_items = contract.functions.getNumItems().call()
21+
22+
# Get the details of a specific luxury item
23+
item_id = 12345
24+
item_details = contract.functions.getItemDetails(item_id).call()
25+
26+
# Add a new luxury item to the contract
27+
new_item = {
28+
'id': 3232 #product_hash-sha,
29+
'name': 'Diamond Necklace',
30+
'description': '18k white gold necklace with 10-carat diamond',
31+
'price': 1000000,
32+
'seller': '0x1234567890abcdef1234567890abcdef12345678'
33+
}
34+
tx_hash = contract.functions.addItem(**new_item).transact({'from': w3.eth.accounts[0], 'gas': 1000000})
35+
receipt = w3.eth.waitForTransactionReceipt(tx_hash)
36+

backend/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hostify

backend/requirements.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)