Back to all courses
Decentralized Autonomous Organizations (DAOs) are the future of the Web. In this episode, we'll build a simple DAO that let's users submit their health data to a marketplace and let's health organizations buy that data, with the proceeds going directly to users. This is an idea I've been toying with for a few weeks as I'm really interested in ways of incentivizing people to be healthy. We'll learn about how DAOs work, then we'll build a toy DAO example. I'll then show you how to build a DAO without coding, then we'll build the Health DAO using Solidity, Truffle, Metamask, Ganache, IPFS, and Javascript. Interspersed in all of this are demos of GitHub's CoPilot tool that I now have access to, which auto-completes your code in an incredible way. Get hype!
I'm a technologist on a mission to spread data literacy. Artificial Intelligence, Mathematics, Science, Technology, I simplify these topics to help you understand how they work. Using this knowledge you can build wealth and live a happier, more meaningful life. I live to serve this community. We are the fastest growing AI community in the world!
This guide will instruct on how to develop a health DAO. A DAO is an independent and decentralized organization.
It has several test data sets uploaded to IPFS, the interplanetary file system, and the Ethereum blockchain has been used to point at each of these data sets.
This is the fifth AlphaCare-related article. You may review the first four before we proceed. You can find them below:
As we construct our DAO, we will utilize RapidAPI Hub to collect Ethereum values in real-time to convert them to USD for display on the front end. This is a marketplace where anyone may submit their health data and upload it by selecting specific files, such as a heart scan, ECG, or blood test.
A user/patient can upload it to IPFS through this health DAO, after which it is listed on this marketplace, and anyone can buy it. It will enable them to access their wallet, from which they can purchase the item. They can earn money for their health data, preferably a passive income, as other health groups, clinics, and hospitals buy it.
That's the basic idea: how can we turn health data into a source of passive income? We'll also utilize GitHub Copilot.
I also want to show you an app called InsideTracker.
I had a blood test performed for InsideTracker and uploaded the results to the platform. It is a centralized, closed-source platform where you pay and receive test results. It provides health-related recommendations using deep learning. You can see an example of a cholesterol test.
My biomarker could also be downloaded as a PDF, which I could then upload to a service. They could examine all of these numbers and pay for this if necessary. Additionally, there is the option to anonymize this data.
As a marketplace, we intend to make something similar open source and pay users for their data. The DAO will be used for this purpose. However, let's begin by defining a DAO as the initial step.
A Decentralized Autonomous Organization (DAO) is a community or group organized around a specific mission and governed by a shared set of rules enforced on the blockchain. DAOs are more transparent than conventional organizations because all actions are visible and verifiable.
The picture below shows a comparison between DAO and the company. Companies like Facebook, Google, and Apple are corporate entities that Web2 has been built around.
Web 2.0 was centered on convenience, and companies owned all of the equity. If they are public, you will receive a small portion of equity after five or six years of value accumulation. But in Web3.0, ownership is more important than convenience. DAOs are the answer to users' desire for ownership in a network rather than convenience.
A DAO is a grassroots initiative that anyone can launch, with no top-down hierarchy. It is an evolution of the company's structure that is inclusive and open to all participants, as opposed to being constrained by various human and geographical factors. Because they occur on a public distributed ledger, i.e., the blockchain, all of the DAO's transactions, as opposed to those of a corporation, will be accessible to the general public.
The other aspect of companies is that they're closed-source because they fear someone will steal their code and no one will profit. We are unable to access Facebook source code. However, the source code for a DAO, a decentralized version of Facebook, would be public. Even if everyone had access to the source code, it would still be profitable.
There are currently thousands of DAOs emerging. A DAO is a transparent online community, similar to Discord, Slack, subreddit, etc., with the addition of collective purchasing power and voting rights. These are the two critical features of a DAO that a standard discord lacks.
Everyone in the DAO can make purchasing decisions or vote on specific proposals, so the power is decentralized to everyone as opposed to the creator of the Discord or subreddit, who acts as a moderator. When examining the DAO stack, we will employ a few key technologies.
The first technology is Solidity. It is the programming language of the Ethereum Blockchain. It is designed for developing smart contracts that run on Ethereum.
You can see a straightforward example here. We import the version of solidity and can generate a contract just as we would for any other type of class object in C or Python.
A class object possesses a set of methods such as a set. In this instance, it involves setting a variable that anyone can transmit via a transaction to a variable stored in the contract. Therefore, it is a simple getter and setter function.
solidity
// SPDX-License-Identifier: GPL-3.0pragma solidity >=0.4.16 <0.9.0;contract SimpleStorage {uint storedData;function set(uint x) public {storedData = x;}function get() public view returns (uint) {return storedData;}}
This smart contract does not reside on a server where we can access it through the HTTP web. We interact with it through blockchain-based transactions. This contract will contain a sum of money and code executed whenever a transaction is sent. Solidity is the programming language used to create these smart contracts.
Now, the second tool is called TRUFFLE. It is the most popular way to write smart contracts in solidity. It is a framework we can download from GitHub.
They have a suite of tools and documentation we can use to build our DAOs on Ethereum using solidity. As we construct a DAO, we can quickly and easily compile and execute smart contracts on a test blockchain.
The third tool we will use is MetaMask. It provides the simplest yet most secure way to connect to blockchain-based applications. You are always in control when interacting on the new decentralized web.
It is available as a browser extension and mobile app; MetaMask equips you with a key vault, secure login, token wallet, and token exchange—everything you need to manage your digital assets.
On the DAO, various operations are possible. In the DAO, we can cast votes, create proposals, spend money, and purchase items, all of which stem here.
The fourth tool is called Remix. It is a no-installation GUI-based tool for creating smart contracts. The remix will get both experts and novices moving in double-quick time. It is compatible with other tools and offers a straightforward deployment process to your chosen chain. It is renowned for its visual debugger.
The remix is the most popular destination for learning Ethereum. We will rely heavily on the remix browser throughout this guide.
The fifth tool is called Ganache. It is a test blockchain that we can run. It is a test version of the Ethereum blockchain that our smart contracts can speak with, and that's just for building test projects.
DAO will consist primarily of smart contracts, but we will also need a user interface written in languages like HTML, CSS, and JavaScript so that the user can control it over an HTTP connection.
This JavaScript library enables the communication between the smart contract and the front end to display wallet information or user information on the front end.
The last piece of technology that we're going to use is the interplanetary file system (IPFS). IPFS is a distributed system for storing and accessing files, websites, applications, and data.
Smart contracts can execute code and perform computation, and we can implement a user interface, but you may wonder, where is all this information kept? Is the Ethereum blockchain the place to keep it? Unfortunately, that is not the case.
The Ethereum blockchain will become unwieldy and highly costly if we store all this data there. Thus, Ethereum functions as a pointer to where the data is stored in this decentralized file storage system known as the Interplanetary File System (IPFS).
Every time I upload a file to IPFS, all the nodes in the IPFS network that earn money through file coin will store a portion of that data as it is split, charted, and distributed across these various nodes.
Therefore, it is not stored on a centralized server but on a decentralized network of IPFS client-running nodes. These are the tools that will be utilized throughout this guide. So let's immediately begin building our first DAO.
This is a simple DAO example from here on GitHub.
This DAO is an extremely basic ice cream vending machine. The fundamental concept is that we will have two smart contracts. The first will be the vending machine itself, and the second will be the DAO.
As participants, we can send transactions to the DAO, which will be called votes. In this simple use case, the DAO sends the vending machine some funds, such as one Ether, and returns a digital cupcake.
Then, as DAO users, we can vote on whether or not to purchase a cupcake. If most users vote yes, the DAO will consider all of their proposals regardless of where they are in the world, and then it will purchase the cupcake. Let’s deploy this in the steps below:
Downloading the Code Simple DAO is our initial step. The digital vending machine and the simple DAO contracts will be uploaded to Remix. Let's begin with an explanation of what is happening here.
In this first Solidity contract, we can see that a single class named vending machine will be created. This vending machine has an owner
. This vending machine has an associated address and a balance indicating how many cupcakes it contains.
In the constructor()
of this class file, we will specify that whoever creates this smart contract will be the owner
of the message.sender
, and the cupcake balances will begin with a hundred cupcakes in this vending machine.
Then there are two additional functions: refill()
and purchase()
. Accordingly, refill()
allows the owner to increase the cupcake balance of the smart contract. It specifies that only the owner
who created this contract via the wallet address in meta mass can refill()
it. Every time we call refill()
, we send the number of cupcakes we wish to add as a parameter, which is then added to the cupcakeBalances
variable. So, that's the first one.
The second function is purchase()
. Every time a DAO member sends a transaction to the vending machine, they must pay a minimum of one Ether. If they do, and there are enough cupcakes, it will subtract the amount from cupcakesBalances
and send a cupcake in the form of an address to the message.sender
. Hence, this is a digital vending machine. We will compile both of these functions.
solidity
// SPDX-License-Identifier: MITpragma solidity 0.6.11;/// @title vending machine smart contract.contract VendingMachine {// Declare state variables of the contractaddress public owner;mapping (address => uint) public cupcakeBalances;// When 'VendingMachine' contract is deployed:// 1. set the deploying address as the owner of the contract// 2. set the deployed smart contract's cupcake balance to 100constructor() public {owner = msg.sender;cupcakeBalances[address(this)] = 100;}// Allow the owner to increase the smart contract's cupcake balancefunction refill(uint amount) public {require(msg.sender == owner, "Only the owner can refill.");cupcakeBalances[address(this)] += amount;}// Allow anyone to purchase cupcakesfunction purchase(uint amount) public payable {require(msg.value >= amount * 1 ether, "You must pay at least 1 ETH per cupcake");require(cupcakeBalances[address(this)] >= amount, "Not enough cupcakes in stock to complete this purchase");cupcakeBalances[address(this)] -= amount;cupcakeBalances[msg.sender] += amount;}}
I will begin with the second contract. The name of the second contract is Simple DAO. So far, we have the vending machine's address that we will later configure. We have a voteEndtime
so that when we initialize this DAO, we can determine how long a vote can take. There is a time limit.
The DAO has a balance
, which indicates how much Ether has been sent into the DAO. It will include a list of balances. It will have a decision, a bullion binary value indicating whether or not the voters have decided to purchase a cupcake, followed by an ended binary value indicating that the voting period has concluded.
We have two distinct structures. The first is a voter()
function, and the second is a proposal()
function. A weight
will be assigned to a voter()
. We now know whether or not we voted. We have an address delegate
and then a vote
. It could be zero or one, yes or no. Each proposal will have a name
and a voteCount
, so it will have a series of voters who voted on it.
Remember that there are numerous ways we could design this, but we have a chairperson
in this instance. Thus, this individual can set up and initiate a vote in the DAO. The array will also contain a list of voters and a collection of proposals
.
Even though there are two error handlers, we can't start the vote if it has already ended. If the vote is still going on, we can still vote. The constructor is a bit more complicated, and in this case, we'll set it to "what is the vending machine?" How long will the voting last, and what are the names of the proposals?
We select the possible proposals, set the address, determine who the chairperson is, determine the length of the vote, and then push all the votes into the proposal array for the duration of the vote. Then we have a DepositEth()
function, which says who can deposit into the DAO Smart contract.
We have a right to vote, and the chairperson can then determine who is eligible to vote to establish a smart contract. We state that if time is still available, anyone may contribute to the vote, but only one ether per voter is permitted. Then there is the actual voting function: If I vote via a proposal, I can say yes or no, and we set the voting parameter to true or false.
Lastly, we have this countVote()
function, which is executed right before the vote has ended, which says, let's count up all the votes, and if all the votes say yes, the DAO then automatically buys the cupcake and then the DAO, meaning all the users, share ownership of all of those cupcakes.
solidity
// SPDX-License-Identifier: MITpragma solidity >=0.7.0 <0.9.0;/// @title Simple DAO smart contract.contract simpleDAO {// This simple proof of concept DAO smart contract sends ether to the digital vending machine// only if the majority of the DAO members vote "yes" to buying digital cookies.// If the majority of the DAO members decide not to send ether, the members who deposited ether can withdraw the ether they deposited.// address of the vending machineaddress payable public VendingMachineAddress;uint public voteEndTime;// balance of ether in the smart contractuint public DAObalance;// allow withdrawalsmapping(address=>uint) balances;// proposal decision of votersuint decision;// default set as false// makes sure votes are counted before ending the votebool ended;struct Voter {uint weight; // weight is accumulated by delegationbool voted; // if true, that person already votedaddress delegate; // person delegated touint vote; // index of the voted proposal}struct Proposal {string name; // short name (up to 32 bytes)uint voteCount; // number of accumulated votes}// address of the person who set up the voteaddress public chairperson;mapping(address => Voter) public voters;Proposal[] public proposals;//error handlers/// The vote has already ended.error voteAlreadyEnded();/// The auction has yet to end.error voteNotYetEnded();// Sample input string: ["buy_cupcakes", "no_cupcakes"]// First item in the string is the one that will execute the purchase// _VendingMachineAddress is the address where the ether will be sentconstructor(address payable _VendingMachineAddress,uint _voteTime,string[] memory proposalNames) {VendingMachineAddress = _VendingMachineAddress;chairperson = msg.sender;voteEndTime = block.timestamp + _voteTime;voters[chairperson].weight = 1;for (uint i = 0; i < proposalNames.length; i++) {proposals.push(Proposal({name: proposalNames[i],voteCount: 0}));}}// anyone can deposit ether to the DAO smart contract// members must deposit at least 1 eth into DAO// this is to avoid complications during withdrawal if the DAO votes to buy cupcakesfunction DepositEth() public payable {DAObalance = address(this).balance;if (block.timestamp > voteEndTime)revert voteAlreadyEnded();require(DAObalance <= 1 ether, "1 Ether balance has been reached");DAObalance = address(this).balance;balances[msg.sender]+=msg.value;}// only the chairperson can decide who can votefunction giveRightToVote(address voter) public {require(msg.sender == chairperson,"Only chairperson can give right to vote.");require(!voters[voter].voted,"The voter already voted.");require(voters[voter].weight == 0);voters[voter].weight = 1;}// proposals are in format 0,1,2,...function vote(uint proposal) public {Voter storage sender = voters[msg.sender];require(sender.weight != 0, "Has no right to vote");require(!sender.voted, "Already voted.");sender.voted = true;sender.vote = proposal;proposals[proposal].voteCount += sender.weight;}// winningProposal must be executed before EndVotefunction countVote() publicreturns (uint winningProposal_){require(block.timestamp > voteEndTime,"Vote not yet ended.");uint winningVoteCount = 0;for (uint p = 0; p < proposals.length; p++) {if (proposals[p].voteCount > winningVoteCount) {winningVoteCount = proposals[p].voteCount;winningProposal_ = p;decision = winningProposal_;ended = true;}}}// Individuals can only withdraw what they deposited.// After EndVote function is run and if proposal "buy_cupcakes" won,// users will not be able to withdraw etherfunction withdraw(uint amount) public{if(balances[msg.sender]>=amount){balances[msg.sender]-=amount;payable(msg.sender).transfer(amount);DAObalance = address(this).balance;}}// ends the vote// if DAO decides not to buy cupcakes, members can withdraw deposited etherfunction EndVote() public {require(block.timestamp > voteEndTime,"Vote not yet ended.");require(ended == true,"Must count vote first");require(DAObalance >= 1 ether,"Not enough balance in DAO required to buy cupcakes. Members may withdraw deposited ether.");require(decision == 0,"DAO decided not to buy cupcakes. Members may withdraw deposited ether.");if (DAObalance < 1 ether) revert();(bool success, ) = address(VendingMachineAddress).call{value: 1 ether}(abi.encodeWithSignature("purchase(uint256)", 1));require(success);DAObalance = address(this).balance;}}
This is a basic example of a DAO, which allows us to interact with a smart contract that grants users are voting and purchasing rights. All network participants share the network. Unlike Facebook, where they control everything, we're mere users.
Let's now deploy these smart contracts using the solidity protocol.
First, we'll compile this digital vending machine using the compiler. For this, we will press the compile button. It will compile, and once the compilation is complete, we will publish it on IPFS. We will then proceed to deploy and execute the transaction. We will proclaim "injected Web3" and then deploy this smart contract.
The contract has now been implemented on the test network. We can see the transaction vending machine and the three previously configured functions. There are three options: purchase
, refill
, and cupcakeBalance
.
After deploying the vending machine, we will now deploy the simple DAO. So we will proceed to the compiler and run. Once it has been compiled, it will be uploaded to IPFS.
Now, we will return to the run contract. We will determine the vending machine's location, the voting time, and a list of proposals that could be yes or no, such as whether we want a cupcake. Once we have these three parameters, we will transact. This will deploy it.
Now it is evident that the basic DAO has also been deployed. Thus, we have two contracts deployed on this test address. We may refill as many cupcakes as desired. All of the functions that we have written are displayed as checkboxes. This is a very simple illustration of how this works.
Let's add some JavaScript. So I'll create a new file, then open RapidAPI Hub and search for the Ethereum price. Because for example, I wish to display the Ethereum price within our DAO. Consequently, this DAO will call Ethereum and indicate the price for users at the time. There are numerous APIs for Ethereum; for example, I want to use the Global Ethereum Price Index - GEX.
So let’s test that endpoint, get the example response, and here's the price for all of these, and that's for Ether to USD.
Go to code snippets; it's in Node.js. I want it to be in JavaScript. Let's use an “(JavaScript) XMLHttpRequest” code snippet.
We will copy the code and put this into a remix and hit compile, and run this.
js
const data = null;const xhr = new XMLHttpRequest();xhr.withCredentials = true;xhr.addEventListener('readystatechange', function () {if (this.readyState === this.DONE) {console.log(this.responseText);}});xhr.open('GET','https://bitcoinaverage-global-ethereum-index-v1.p.rapidapi.com/indices/ticker/custom/include/ETHUSD?exchanges=bitfinex%2Cbitstamp');xhr.setRequestHeader('X-RapidAPI-Key', 'your-rapidapi-key');xhr.setRequestHeader('X-RapidAPI-Host', 'bitcoinaverage-global-ethereum-index-v1.p.rapidapi.com');xhr.send(data);
So now that script has been compiled in the JavaScript compiler, that will call the API to get the Ethereum price Index using RapidAPI. That's the first simple example of a DAO.
Let's explore some DAOs examples below.
Let's get into some more complex examples of existing mature DAOs. It's called VitaDAO. They are a decentralized collective that funds early-stage longevity research.
Ordinarily, longevity labs are exceptionally closed, with all data and voting power sequestered. In this case, however, everything is occurring in the open.
So I can launch the DAO on Ethereum Mainnet (ERC 20) token. I can see a bunch of active proposals here, which means many people have voted on different things we can do for the DAO.
This was an example of let's have an appropriate treasury strategy. We can hold Vita, Ether, and stable coins and hear the details of the proposals, i.e., how to reallocate all this money and how to create liquidity and all this stuff.
This is a collection of smart contracts on the Ethereum blockchain, but we're accessing it via HTTP web because Web3.js is being used to display the smart contract data on the front end for users. We can vote on this using our VITA tokens as users. We can review existing proposals and also vote on them.
Connecting our wallet enables us to transact with all of this stuff. Moreover, we can also stake our VITA token.
There's another DAO I want to show you called Shiba Swap. It is the decentralized exchange that the Shiba token is built on top of the Shiba token. So, Shiba Swap is an HTTP website, but all smart contracts are being called from Web3.js or JavaScript.
You can see that you have a shib, leash, and bone; these are tokens. What we can do is we can bury a bone. There are a bunch of things we can do. We can buy and sell NFTs at Shiba Swap. That'll allow us to buy NFTs using our shib tokens. We can swap our coins by digging. Also, we can find a pair of liquidity pairs.
Gitcoin is a much more interesting one. It is a decentralized bounty for developers to build and get paid for different tasks that different companies have, and they get paid in this Gitcoin token that they built.
Gitcoin allows users to earn money, connect with others, and fund projects. All of this utilizes Web3. I can also link it to my wallet, allowing me to fund a series of projects or receive a grant for work. I can also investigate what bounties are available, perform work, and be compensated in a decentralized setting.
Before we get to the easy way of building a DAO, let me show you GitHub Copilot first. It is a language model trained on billions of lines of code. It turns natural language prompts into coding suggestions across dozens of languages.
It can also predict the next likely programmatic statement you will write. It's a prediction engine that can predict what the next likely code is going to be. So let's take a look at this.
This also functions as a Visual Studio Code plugin. I'm able to enter Python code here. Let's say we want to develop a Data science application that trains on some linear regression data using XYZ housing price coordinates.
You will notice that it automatically fills in. You can try this sample code as an example:
py
import numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animationimport sysimport osimport timeimport mathimport randomimport csvimport copydef get_data(filename):data = []with open(filename, 'r') as csvfile:plots = cv.reader(csvfile, delimiter=',')for row in plots:data.append(row)return datadef set_data(data) :x = []y = []z= []for i in range(0, len(data)) :x.append (data[i] [0])y.append (data[i] [1])z.append (data [i] [2])return x, y, zdef build_graph(x, y, z):fig = plt.figure()ax = fig.add_subplot(111, projection='3d')ax.scatter(x, y, z, c='r', marker='o')plt.show()def build_model(x, y, z):model = []for i in range(0, len(x)):model.append([x[i], y[i], z[i]])return modeldef linear_regression(model):x = []y= []z = []for i in range(0, len(model)) :x.append(model[i] [0])y.append (model[i][1])z.append (model [i][2])x = np.array(x)y = np.array(y)z = np.array(z)x = x. reshape(-1, 1)y = y. reshape(-1, 1)z = z. reshape(-1, 1)from sklearn.linear_model import LinearRegressionregressor = LinearRegression()regressor. fit(x, y)regressor.fit(x, z)print(regressor.coef_)print(regressor.intercept_)return regressor.coefregressor. Interceptdef main():ata = get_data( 'data.csv')print (ata)# print(ata[0][01)# print(ata[0][1])# print(ata[0][21)# print(ata[0][3])
The easiest way to build a DAO is by using the tool Aragon. It is a no-code tool to build a DAO, and it is like a meta DAO, which helps you build DAOs, and you can do all this from the web.
Let's create a DAO in Aragon. It will be an Aragon Govern (ERC 20 token) built on Ethereum. This will open the Argon DAO and let you build your own DAO. My wallet is connected via a meta mask. I'll click on Create DAO and call it “health_dao”.
It now has a new token. The token will be referred to as a longevity token. It has a symbol labeled LONGV. I can enter any number in the Number of tokens field. The delay in execution could be one day. After reviewing the agreement, establish and confirm My DAO.
The rules are being uploaded to IPFS. It is integrated into the meta mask and will generate a DAO. Because this is not on the mainnet, it will cost me money; however, if I switch to the testnet, I will not be charged. Then, you can create an organization using any available template.
The DAO has been created, and you are now viewing its dashboard. I can create a variety of actions, including going to finance to see what transactions exist, settings to create a new action, and possibly a proposal.
You can see that that's the basic idea here. So that's Argon. That's a really easy way. Now let's get to the demo we're going to build here.
We're going to build a health DAO marketplace, and we'll start with their pet shop tutorial.
We can follow their tutorial and turn this pet shop, a decentralized pet shop where anyone can buy and sell pets, into a decentralized health marketplace by replacing some of the variables.
The first step is to open up the terminal. Truffle initializes in the current directory, so first create a directory in your development folder of choice and then move inside it.
sh
mkdir pet-shop-tutorialcd pet-shop-tutorial
After that, we'll install truffle:
sh
sudo npm install -g truffle
We've created a special Truffle Box just for this guide called pet-shop
, which includes the basic project structure as well as code for the user interface. Use the truffle unbox
command to unpack this Truffle Box.
sh
truffle unbox pet-shop
This will be a good starting template for us. Okay, so now we're going to look at the project directory that it's created for us.
The first is the contracts
folder, which contains some basic smart contracts. We're going to have migrations.sol
, some node_modules
, etc., and we have a config
file as well; that's where we're going to deploy it.
Let's proceed to the variable setup. There are numerous functions that we wish to add to our smart contract. I've already added all of this, so I will not display it again in this guide.
Nonetheless, there is a list of adopters. In our case, these adopters will be health organizations, and there is a pet adoption function. Rather than adopting, a health data set is purchased in this case. To deploy the server, we must now compile, migrate, test, and run it:
sh
sublimetruffle compile
We also need to download ganache. It will speak to this blockchain back and forth by sending transactions. When I migrate it, it will migrate everything I have here into the blockchain.
sh
truffle migrate
When we deploy the app, we can see health DAO published on our dashboard.
Now, I want to write some Web3.js code using co-pilot. So let's open a Visual Studio Code, and we'll create a new JavaScript file.
Let's say we're going to add web3.js
here, and I can take assistance from the co-pilot. Let's say we want to get a balance
. Also, we want to add data to IPFS; hence we need to integrate this into our code. We can also node
using co-pilot after that.
js
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));web3.eth.getAccounts().then(accounts => {console.log(accounts);});web3.eth.getAccounts().then(accounts => {console.log(accounts);});web3.eth.getBalance(accounts[0]).then(balance => {console.log(balance);});const node = await IPFS.create();const data = 'Hello, <YOUR NAME HERE>';//add your data to to IPFS - this can be a string, a Buffer,// a stream of Buffers, etcconst results = node.add(data);//we loop over the results because 'add' supports multiple// additions, but we only added one entry here, so we only see// one log line in the outputfor await (const { cid } of results) {// CID (Content IDentifier) uniquely addresses the data// and can be used to get it againconsole.log(cid.toString());}node.IPFS.cat(cid, (err, stream) => {if (err) {console.error(err);return;}stream.pipe(process.stdout);});
Let’s go back to sublime text editor. The basic idea here is that we allow someone to adopt a pet, and then we can retrieve the adopters. We compile that using truffle. We also have features such as configuration, source code, data set, and index file.
Additionally, screenshots can be uploaded and stored on IPFS. Once listed, the item is synchronized with your wallet. You can purchase it, with the proceeds going to the DAO address. Regardless of how we organize it, all voters will have access. Now, there is something else I would like to show you.
Let's say we've built a DAO with smart contracts, a front end, and IPFS-directed data storage. But how do we deploy it for use by others on the HTTP web so that they can access it through their browser?
The answer is we're going to use a service called Fleek, and what it does is it allows us to deploy a decentralized application to IPFS.
I will log in to my GitHub account and add a new site. This enables continuous deployment, so we can store it if we upload it to GitHub. This now provides us with a highly centralized storage location we can view as a dashboard. However, all the data is stored on IPFS.
This guide has taught us how DAOs function, and we've constructed a toy DAO example. We have also seen how to construct a DAO without using code, and we have constructed the Health DAO using Solidity, Truffle, Metamask, Ganache, IPFS, and JavaScript. All of this is interspersed with demonstrations of GitHub's CoPilot tool, which auto-completes your code in an incredible manner.