c8cb40b1b5 | ||
---|---|---|
.. | ||
client | ||
.dockerignore | ||
.gitignore | ||
.soliumignore | ||
.soliumrc.json | ||
Dockerfile | ||
README.md | ||
package.json | ||
server.js | ||
setup.sh | ||
yarn.lock |
README.md
Decentralized & Collaborative AI on Blockchain Demo
A dashboard and examples for deploying updatable AI models to Ethereum.
This folder also contains Solidity examples for models, data handlers, and incentive mechanisms for deploying models that are free to use for inference as initially proposed in our introductory paper.
This project is made from a React project with Truffle added. This Truffle example was used to help add Truffle.
This work in its current form is just meant as an example and proof of concept. It is not ready to be deployed for production yet.
Setup
This section explains how to set up locally on Linux/WSL, alternatively, you can skip ahead and use a Docker image.
The following steps are made for Linux and require npm
. They do work in WSL.
Run
./setup.sh
Docker Setup
You can use a Docker image by running:
docker run --rm -it -p 3000:3000 -p 5387:5387 -p 7545:7545 -v ${PWD}:/root/workspace/demo -v /root/workspace/demo/node_modules -v /root/workspace/demo/client/node_modules --name decai-demo mcr.microsoft.com/samples/blockchain-ai/0xdeca10b-demo bash
# So that you can start a few processes in the Docker container, run:
byobu
Building the Docker Image
If you want to build your own fresh image:
docker build -t decai-demo .
Troubleshooting Setup
If you have problems running the setup steps related to node-gyp, then you might need to set Python 2.7 to be your default. Recommendation: Set up a Python 2.7 Conda environment and activate it.
Update
To update dependencies after already setting up:
yarn global upgrade yarn && yarn upgrade && (cd client && yarn upgrade)
Deploy
Blockchain
Start the blockchain (Ganache) in one terminal. Run:
yarn blockchain
Do once:
- Add http://localhost:7545 to MetaMask.
- Copy the first private key output.
- Use that private key to create a new account in MetaMask.
Server
Start the server in one terminal. Run:
yarn server
Client
Then in another terminal. Run:
yarn client
Troubleshooting Deployment
Blockchain Issues
Run yarn clean
to delete your local blockchain and cached contracts. This will delete any transactions done but should make everything work again.
Errors about a contract not found at a certain address
If you get errors about calling a contract then it's probably because you restarted your blockchain (Ganache) and the contract doesn't exist anymore on the blockchain. This would happen if you restarted your computer. You have to delete the generated .json files that keep track of contract addresses:
rm -f client/{build,src}/contracts/*.json
Then you should be able to deploy normally.
You can also try to rm -rf blockchain_db
to delete your blockchain and restart from scratch.
MetaMask Issues
Issues about nonce
If MetaMask gives issues about the nonce not being right for a transaction then it's probably because you restarted your blockchain but MetaMask caches some basic things on the URL and the network ID.
You can first try to reset your account in the MetaMask settings. This will clear your transaction history.
You shouldn't need to if you've been consistently using a blockchain for just this project but you can also try changing the network ID for Ganache. This can be done in the Ganache UI or CLI (--networkId).
MetaMask Loading Issues
If MetaMask is spinning and non-responsive:
- Disable the extension here: chrome://extensions
- Re-enable the extension.
- Open the extension.
- Change the network to use. E.g. Select Main Ethereum Network.
- Log in to MetaMask.
- Change the network back to the custom one.
- Reject any queued transactions.
If you get the spinning issue again, then also try following the steps above with resetting your account as well as restarting the blockchain by:
- Stop the
yarn blockchain
process. - Run
yarn clean
. - Run
yarn blockchain
.
Testing
Run
yarn test
A local blockchain will be started and stopped so it's best not to have a blockchain running at the same address and port (e.g. one running through yarn blockchain
).
Linting
Solidity Files
We use Ethlint for linting and enforce it on pull requests. To check the contract code run:
yarn lint