当前位置: 首页 > Web前端 > HTML

web3.0社交平台投票系统开发智能合约部署源码详解(DAO)

时间:2023-03-28 13:04:42 HTML

“Web3”是指“基于区块链的去中心化在线生态系统”。2021年,Web3的想法开始流行起来。到2021年底,特别兴趣激增,主要是由于加密货币爱好者的兴趣以及知名技术人员和公司的投资。Web3的核心区别在于商业模式的去中心化。从这个意义上说,它标志着互联网的第三阶段(因此得名“Web3”)和用户当前现状的逆转。Web3是可以颠覆这种权力结构的下一个迭代,将其转移回用户。开放标准和协议可以回归。其目的是控制不再集中在大型平台和聚合器中,而是通过“无需许可”的去中心化区块链和智能合约广泛分布。这在实践中意味着什么?从本质上讲,它可以通过将去中介化作为核心要素来开发I34-contractI633-deploy53I9,标志着数字应用商业模式的范式转变。在数据、功能和价值方面可能不需要中介。用户和创作者可以占据上风,并且有了开源而非专有应用程序,就会有创新、测试、构建和扩展的动力。HTML的代码如下:HelloWorldDApp

一个简单的投票应用

候选人投票Alice鲍勃卡里
投票新建一个名为app.js的js文件,js代码如下:abi=JSON.parse('[{“常量”:真,“输入”:[{“名称”:“候选人”,“类型”:“bytes32”}],“名称”:“totalVotesFor”,“输出”:[{“名称”:"","类型":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"candidate","type":"bytes32"}],"name":"validCandidate","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"votesReceived","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs“:[{“名称”:“”,“类型”:“uint256”}],“名称”t;:"candidateList","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"candidate","type":"bytes32"}],"name":"voteForCandidate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"candidateNames","type":"bytes32[]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]')VotingContract=web3.eth.contract(abi);//部协地址contractInstance=VotingContract.at('0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');candidates={"Alice":"candidate-1","Bob":"candidate-2","Cary":"candidate-3"}functionvoteForCandidate(){console.log(candidate);candidateName=$("#candidate").val();console.log(candidateName);contractInstance.voteForCandidate(candidateName,{from:web3.eth.accounts[0]},function(){让div_id=candidates[candidateName];console.log(contractInstance.totalVotesFor.call(candidateName).toString());$("#"+div_id).html(contractInstance.totalVotesFor.call(candidateName).toString());});console.log(contractInstance.totalVotesFor.call(candidateName).toString());}$(document).ready(function(){candidateNames=Object.keys(candidates);for(vari=0;i