This project implements a distributed application for an NFT e-commerce, built in Flask, based on smart contract interactions between a remote wallet (e.g. Metamask) and an ethereum blockchain. The DAPP uses Web3.js for the communication with Metamask and the blockchain instance running on Ganache.
- Blockchain instance running on whatever platform (Ganache, Infura, Truffle, etc...)
- Remote wallet browser extension
- Web3.js library
- Web3.py for Python debugging tests
pip install -r requirements.txt
This project uses Ganache-cli to run the blockchain instance with a specific set of accounts which can be exported by the wallet browser extension (e.g. Metamask).
ganache-cli --networkId=1337 --db="./instance/blockchain" --gasLimit=20000000 [--account="0x<Account private key>,<Balance in Wei>"]
The DAPP is associated with admin address in the blockchain. This address is responsible for the deploying of DEX contract. You have to add the admin credentials (address and private key) in the file admin_info.json in the utils directory. This json must have the following structure:
{
"address": "<admin address>",
"private_key": "0x<admin private key>"
}
Second you have to compile and deploy the smart contract of the DAPP.
python deployDex.py
If Everything goes well, you see something like following:
Contract saved: DEX
Contract saved: ERC20Token of DEX
Contract saved: ERC721Token of DEX
If you want to run the application you need to execute the following command:
python app.py -web3-protocol="http" -web3-host="127.0.0.1" -web3-port="8545" -blockchain-networkId="1337"
The application will be located at the link http://127.0.0.1:5000
If you want to test the DEX contract, you have to add two different acoounts in the file test_accounts.json in the utils directory. This json must have the following structure:
{
"<buyer address>": "0x<buyer private key>",
"<seller address>": "0x<seller private key>",
}
In order to run the test, you have to execute the following command:
python testContract.py
- This project run the web server and the ganache enviroment on the same machine. So if you want to change the server configuration you have to edit the file server_info.json in the utils directory.
- In order to run properly the script testContract.py, the blockchain must contain the same accounts and private keys of those contained in test_accounts.json in the utils directory