DevChain
No gas needed. Accounts are only for identification purposes.
See the dapp in action
DEMO: A voting dappStep 1
Step 2
2.1 Copy and paste the following code to the contract section of BUIDL.
pragma solidity >= 0.4.0;
contract Vote {
string public greeting;
string public photoUrl;
mapping (address => int) votes;
uint ups;
uint downs;
constructor(string _greeting, string _photoUrl) public {
greeting = _greeting;
photoUrl = _photoUrl;
}
function vote (int _choice) public {
require (votes[msg.sender] == 0);
require (_choice == 1 || _choice == -1);
votes[msg.sender] = _choice;
if (_choice == 1) ups++;
if (_choice == -1) downs++;
}
function getVotes () view public returns (uint, uint) {
return (ups, downs);
}
function getVote (address _addr) view public returns (int) {
return votes[_addr];
}
}2.2 Click on Compile and you will see the following. Enter your text and image URL to be voted on, and then click on deploy on chain.


2.3 Go to the dapp section. Click on the Resources tab, and add the following as resources.
2.4 Next, copy and paste the following HTML code into the HTML editor.
2.5 Copy and paste the following JavaScript code into the JS editor.
2.6 Click on Run to see the dapp in action! You can now vote thumb up or down inside BUIDL.

2.7 Finally, you can publish the dapp.
Last updated
Was this helpful?