├── .gitignore ├── README.md ├── bs-config.json ├── client ├── app.js ├── index.html ├── main.css └── ui.js ├── contracts ├── Migrations.sol └── TasksContract.sol ├── migrations ├── 1_initial_migration.js └── 2_deploy_tasks.js ├── package-lock.json ├── package.json ├── screenshot.png ├── test ├── .gitkeep └── TasksContract.js └── truffle-config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DTasksApp 2 | Decentralize App is a simple Tasks' App to practice the creation of a blockchain applicaciont using Solidity and Javascript. 3 | 4 |  5 | 6 | The stack and tools of this application is: 7 | * Truffle Framework 8 | * Ganache 9 | * Solidity 10 | * Nodejs 11 | * Bootstrap -------------------------------------------------------------------------------- /bs-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "server": { 3 | "baseDir": [ 4 | "./client", 5 | "./build/contracts" 6 | ], 7 | "routes": { 8 | "/libs": "./node_modules" 9 | } 10 | }, 11 | "port": "3001" 12 | } -------------------------------------------------------------------------------- /client/app.js: -------------------------------------------------------------------------------- 1 | App = { 2 | contracts: {}, 3 | init: async () => { 4 | await App.loadWeb3(); 5 | await App.loadAccount(); 6 | await App.loadContract(); 7 | await App.render(); 8 | await App.renderTasks(); 9 | }, 10 | loadWeb3: async () => { 11 | if (window.ethereum) { 12 | App.web3Provider = window.ethereum; 13 | await window.ethereum.request({ method: "eth_requestAccounts" }); 14 | } else if (web3) { 15 | web3 = new Web3(window.web3.currentProvider); 16 | } else { 17 | console.log( 18 | "No ethereum browser is installed. Try it installing MetaMask " 19 | ); 20 | } 21 | }, 22 | loadAccount: async () => { 23 | const accounts = await window.ethereum.request({ 24 | method: "eth_requestAccounts", 25 | }); 26 | App.account = accounts[0]; 27 | }, 28 | loadContract: async () => { 29 | try { 30 | const res = await fetch("TasksContract.json"); 31 | const tasksContractJSON = await res.json(); 32 | App.contracts.TasksContract = TruffleContract(tasksContractJSON); 33 | App.contracts.TasksContract.setProvider(App.web3Provider); 34 | 35 | App.tasksContract = await App.contracts.TasksContract.deployed(); 36 | } catch (error) { 37 | console.error(error); 38 | } 39 | }, 40 | render: async () => { 41 | document.getElementById("account").innerText = App.account; 42 | }, 43 | renderTasks: async () => { 44 | const tasksCounter = await App.tasksContract.tasksCounter(); 45 | const taskCounterNumber = tasksCounter.toNumber(); 46 | 47 | let html = ""; 48 | 49 | for (let i = 1; i <= taskCounterNumber; i++) { 50 | const task = await App.tasksContract.tasks(i); 51 | const taskId = task[0].toNumber(); 52 | const taskTitle = task[1]; 53 | const taskDescription = task[2]; 54 | const taskDone = task[3]; 55 | const taskCreatedAt = task[4]; 56 | 57 | // Creating a task Card 58 | let taskElement = `
Task was created ${new Date( 71 | taskCreatedAt * 1000 72 | ).toLocaleString()}
73 | 74 |