This is the second post in a series on how to use current Ethereum tools to create smart contracts with no programming experience required. Download the latest version of Ethereum Wallet, read the first part and let’s have fun!
Creating a token is fun, but what is the value of a token that doesn’t do anything new? Now we are going to create a new contract that uses the tokens we just created. The contract will be a Democratic organization that lives on the blockchain and that anyone with a stock token will be able to vote on the proposals.
So let’s go back to “contracts” and so “implementation contract” and paste the dao source code about him “Source of Solidity” field. Choose the “Democracy” contract in the Chooser, and then select these parameters:
- About him Amount you can add any amount of ether you want your DAO to start with. Since you can send ether to it at any time in the future, if this is your first time doing so, keep the amount at 0 and send the money later.
- About him actionsdirection field, paste the address of the token contract you just created. Look at the icon and color of the little circle that appears next to the address. If it doesn’t exactly match the one in the contract you created earlier, then there is an error.
- In Minimum shares to vote choose what is the minimum quorum of shareholders that need to vote on an issue before it is approved. Here you should put the integer number of the minimum possible token, so if you created a token with 2 decimal places, putting 500 here will mean that for a proposal to run, the number of votes must be more than 5% of the total shares. of the company
- minutes to discuss: this is the minimum time that a proposal must be discussed and voted on before the results can be counted. Put a small number like 10 minutes if you just want to build something to test, but put something like 20,000 if you want to store large amounts of ether, so all proposals need to stay there for at least two weeks.
Your contract should look something like this:
After a few seconds, you will be redirected to the control panel where you will see how your new contract is created:
You can also see the link to the new contract in the “Contracts” tab. If it’s not there (for example, if you’re adding a contract you didn’t create), you’ll need to add it manually. To add that, you’ll need the address of the contract and its JSON interface, a text string that tells the wallet how to interact with the code. You can choose the name you want and click OK.
Click on the box for your new contract and you will see a contract page. If you haven’t deposited some ether into that contract yet, click deposit and put in a small amount of ether so you can test how this particular democracy works. If the contract already has some funds, click the “show contract information” button.
About him “read the contract” you can see all the functions you can run for free in the contract as they are just reading information from the blockchain. Here you can see, for example, that “sharesTokenAddress” is indeed the correct address, or that there are currently 0 proposals in the contract. Let’s change that.
About him “Write to Hire” it has a list of all the functions that will try to do some computation that saves data to the blockchain and therefore will cost ether. Select “newProposal” and it will show you all the option options for that feature.
For “recipient”, add the address of someone you want to send ether to, then enter how much ether you want in “etherAmount” (must be an integer), and finally some text describing the reason you want to do this. Leave the transactionByteCode blank for now. Click run and type your password. After a few seconds, the number of proposals will increase to 1 and the first proposal, number 0, will appear in the left column. As you add more proposals, you can view any of them by simply putting the proposal number in the “proposals” field and you can read all about it.
Voting on a proposal is also very simple. Choose “vote” in the feature selector. Write the Proposal Number in the first box and check the “Yes” box if you agree with it (or leave it blank to vote against). Click on “run” to submit your vote.
When the minimum voting time has passed, you can select “runProposal”. If the proposal was to simply send ether, you can also leave the “transactionBytecode” blank field. After pressing “execute” but before typing your password, pay attention to the screen that appears. If there is a warning in the “estimated tariff consumption” field, it means that for some reason the called function did not work. will execute and be terminated abruptly.It can mean many things, but in the context of this contract, this warning will appear whenever you try to execute a contract before its deadline has passed, or if the user is trying to send a bytecode different data than the original proposal had For security reasons, if any of these things happen, the performance of the contract is terminated abruptly and the user who attempted the illegal transaction will lose all the ether they sent to pay the transaction fees.
If everything went well, you should be able to see the voting results in a few seconds. He “open to vote” parameter in the first frame will change to false while the proposalapproved It will reflect whether the proposal has been accepted or not. You should also be able to see that the Ether balance of the contract will decrease and the equivalent Ether will be sent to the recipient of the Ether you wanted to send.
Now take a moment to let it in: You’ve just created an organization that only exists on the blockchain, that obeys fully digital token-based votes, but can still move real value and create a very real impact in the world. Also keep in mind that the organization is no longer in your control: you’ll run only the exact code you used to create it, forever. You can’t bribe it, you can’t assign it, and the same rules apply whether you’re moving 0.01 or 1,000,000 ethers.
Can it get better than this? Actually, it can. In our next post, we’ll explore how you can use “transactionBytecode” to allow the DAO to execute any type of ethereum transaction., including owning or creating other contracts. We will also modify the token code to allow the DAO to control how much of a token is in circulation and how to send it.