Hello Friends !! Here we are with our much-awaited blog of the series Create To-do list app using Ethereum Blockchain. In Part-1, Part-2 we have set up a project, created a smart contract, and deployed on ethereum blockchain using metamask and performed the test.
In this part, we will create tasks for the client-side application to interact with the todo list smart contract. You’ll need to create the following files for your project:
Create Task
We’ve already created a function for creating tasks, but it is not complete. That’s because I want to trigger an event any time that a new task is created. So add below TaskCreated event and call from creat task function.
Let’s create a test to ensure that this event is triggered any time a new task is created. We will inspect the transaction receipt when the new task is created. This will contain all of the log information that will contain the event data.
it('creates tasks', async () => {
const result = await this.todoList.createTask('A new task')
const taskCount = await this.todoList.taskCount()
assert.equal(taskCount, 2)
const event = result.logs[0].args
assert.equal(event.id.toNumber(), 2)
assert.equal(event.content, 'A new task')
assert.equal(event.completed, false)
})
Run Test
$ truffle test
Now let’s deploy a new copy of the smart contract to the blockchain since the code has changed.
$ truffle migrate –reset
For enabling input box for creating task, un-comment the form code in the index.html file.
Now enter some task name in the input box and enter .task will be added. To perform transaction it will ask confirmation of metamask.
Implement Complete Tasks
They will appear in the “completed” list, struck through.We’ll add a TaskComplted() event, and trigger it inside a new toggleCompleted() function like this.
Now, find a task in the client-side application and click the checkbox. Once you sign this transaction, it will check off the task from the todo list! Please refer to the code Github. Hope you all will like this final part of this blog series. Please share and subscribe Flexmind site for more wonderful articles.
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Connect with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.