- Using Ganache UI (RPC Server is: HTTP://127.0.0.1:8545). Import the first account to MetaMask.
- Deploy the contract:
truffle migrate
- Test the contract (optional):
truffle test test/Tickets.js
- Install all the dependencies that was registered in the package.json (including web3, parcel, bootstrap, etc..) and run the project:
cd client
npm install
npm run start
Finally, connect your current account to the localhost server
Buying ticket:
Ganache Back-end console with current contract balance:
Current transaction information:
Commands used for creating client directory and dependencies:
mkdir client
cd client
npm init -f
npm install --save-dev parcel
npm install --save web3 bootstrap
Connect to MetaMask using HTML & JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Test</title>
</head>
<body>
<script>
async function connect() {
if ( typeof window.ethereum !== "undefined") {
ethereum.request({method: "eth_requestAccounts"});
}
}
</script>
<button id="connectButton" onclick="connect()">Connect!</button>
</body>
</html>
REMINDER: If reboot and reconnect the Ganache UI, reinstalling npm dependencies is needed:
rm -rf node_modules
npm install
npm run start
Original auther: https://www.youtube.com/watch?v=FYhZPovlGZQ https://www.youtube.com/watch?v=JXa_Y-17Oj4