当前位置: 首页 > news >正文

一号建站门户网站推广介绍方案

一号建站,门户网站推广介绍方案,长沙网站制作公司哪家好,南京做网站南京乐识好题记 用Web3实现前端与智能合约的交互#xff0c;以下是操作流程和代码。 准备ganache环境 文章地址#xff1a;4.DApp-MetaMask怎么连接本地Ganache-CSDN博客 准备智能合约 文章地址#xff1a; 2.DApp-编写和运行solidity智能合约-CSDN博客 编写index.html文件 !…题记 用Web3实现前端与智能合约的交互以下是操作流程和代码。 准备ganache环境 文章地址4.DApp-MetaMask怎么连接本地Ganache-CSDN博客  准备智能合约  文章地址 2.DApp-编写和运行solidity智能合约-CSDN博客 编写index.html文件 !DOCTYPE html html head     titleName Contract Demo/title     !--导入web3库--     script srchttps://cdn.jsdelivr.net/npm/web31.5.2/dist/web3.min.js/script     script     // 检查Metamask是否已安装     if (typeof window.ethereum ! undefined) {     console.log(Metamask已安装);     }     // 设置Web3.js提供者为Metamask     const provider window.ethereum;     const web3 new Web3(provider);     // 请求Metamask连接到以太坊网络     provider.request({ method: eth_requestAccounts })     .then(() {       console.log(Metamask已连接到以太坊网络);     })     .catch((err) {       console.error(无法连接到以太坊网络, err);     });     function setName() {     // 合约地址     const contractAddress 0x32FDC4E86421143b1c27dE49542Bc8ECE2B162a0;     // 合约ABI     const contractABI [     {         inputs: [             {                 internalType: string,                 name: _name,                 type: string             }         ],         name: setName,         outputs: [],         stateMutability: nonpayable,         type: function     },     {         inputs: [],         name: getName,         outputs: [             {                 internalType: string,                 name: ,                 type: string             }         ],         stateMutability: view,         type: function     }     ];     const contract new web3.eth.Contract(contractABI, contractAddress);     const name document.getElementById(name).value;     // 替换为您的账户地址web3.eth.defaultAccount     const fromAddress 0x4e8eB4d1C203929074A3372F3703E556820fEA57;     //contract.methods.setName(name).send({from: fromAddress})     contract.methods.setName(name).send({from: fromAddress})     .on(transactionHash, function(hash){         console.log(Transaction Hash:, hash);     })     .on(receipt, function(receipt){         console.log(Transaction Receipt:, receipt);     })     .on(error, function(error){         console.error(Error:, error);     });     }     function getName() {     // 合约地址     const contractAddress 0x32FDC4E86421143b1c27dE49542Bc8ECE2B162a0;     // 合约ABI     const contractABI [     {         inputs: [             {                 internalType: string,                 name: _name,                 type: string             }         ],         name: setName,         outputs: [],         stateMutability: nonpayable,         type: function     },     {         inputs: [],         name: getName,         outputs: [             {                 internalType: string,                 name: ,                 type: string             }         ],         stateMutability: view,         type: function     }     ];     const contract new web3.eth.Contract(contractABI, contractAddress);     contract.methods.getName().call()     .then(function(result) {         console.log(Name:, result);         document.getElementById(nameValue).innerText result;     })     .catch(function(error) {         console.error(Error:, error);     });     }     /script /head body     h1设置姓名/h1     label forname姓名:/label     input typetext idname     button οnclicksetName()设置姓名/button     br     button οnclickgetName()得到姓名/button     br     span idnameValue/span /body /html !DOCTYPE html html headtitleName Contract Demo/title!--导入web3库--script srchttps://cdn.jsdelivr.net/npm/web31.5.2/dist/web3.min.js/scriptscript// 检查Metamask是否已安装if (typeof window.ethereum ! undefined) {console.log(Metamask已安装);}// 设置Web3.js提供者为Metamaskconst provider window.ethereum;const web3 new Web3(provider);// 请求Metamask连接到以太坊网络provider.request({ method: eth_requestAccounts }).then(() {console.log(Metamask已连接到以太坊网络);}).catch((err) {console.error(无法连接到以太坊网络, err);});function setName() {// 合约地址const contractAddress 0x32FDC4E86421143b1c27dE49542Bc8ECE2B162a0; // 合约ABIconst contractABI [{inputs: [{internalType: string,name: _name,type: string}],name: setName,outputs: [],stateMutability: nonpayable,type: function},{inputs: [],name: getName,outputs: [{internalType: string,name: ,type: string}],stateMutability: view,type: function}]; const contract new web3.eth.Contract(contractABI, contractAddress);const name document.getElementById(name).value;// 替换为您的账户地址web3.eth.defaultAccountconst fromAddress 0x4e8eB4d1C203929074A3372F3703E556820fEA57; //contract.methods.setName(name).send({from: fromAddress})contract.methods.setName(name).send({from: fromAddress}).on(transactionHash, function(hash){console.log(Transaction Hash:, hash);}).on(receipt, function(receipt){console.log(Transaction Receipt:, receipt);}).on(error, function(error){console.error(Error:, error);});}function getName() {// 合约地址const contractAddress 0x32FDC4E86421143b1c27dE49542Bc8ECE2B162a0; // 合约ABIconst contractABI [{inputs: [{internalType: string,name: _name,type: string}],name: setName,outputs: [],stateMutability: nonpayable,type: function},{inputs: [],name: getName,outputs: [{internalType: string,name: ,type: string}],stateMutability: view,type: function}]; const contract new web3.eth.Contract(contractABI, contractAddress);contract.methods.getName().call().then(function(result) {console.log(Name:, result);document.getElementById(nameValue).innerText result;}).catch(function(error) {console.error(Error:, error);});}/script /head bodyh1设置姓名/h1label forname姓名:/labelinput typetext idnamebutton onclicksetName()设置姓名/buttonbrbutton onclickgetName()得到姓名/buttonbrspan idnameValue/span /body /html执行程序  使用vscode的Live Server打开网页 参考这篇文章的执行方法1.Vue-在独立页面实现Vue的增删改查-CSDN博客  展示图  发起交易  完成交易  后记 觉得有用可以点赞或收藏
http://www.pierceye.com/news/445566/

相关文章:

  • 网站站内优化案例自己做的网页怎么上传网站吗
  • 深圳制作网站有用吗如何做网站优化
  • 皖住房建设厅网站the 7 wordpress
  • 怎么自己学着做网站写网站代码
  • 自己电脑上做的网站 怎么让别人看怎么做网站在谷歌
  • 同一ip 网站 权重怎样做才能发布你的网站
  • 上海利恩建设集团有限公司网站社交网站先做pc站可以吗
  • 用网站做淘宝客新媒体销售好做吗
  • 手机模板的网站哪个好wordpress关闭google字体
  • 医疗行业网站怎么做网站反链和外链的区别
  • html网站开发事例教程一起做网店官网下载
  • 中小企业网站优化锦州网站制作公司
  • 谁会在掏宝网上做网站网站开发与设计课程设计
  • 公司网站建设的改进的建议前潮网络网站建设
  • 济宁500元网站建设wordpress 安装错误
  • 网站建设周记网站建设公司面临的问题
  • 网站可视化编辑普通网站与营销型网站有什么区别
  • 网站 手机 微信 app福建网站开发企业
  • 台州网站制作推广net网站开发教程
  • seo的网站点个赞科技 网站制作
  • 百合网 网站 开发做推广都有什么网站
  • 娄底建设网站的公司wordpress 五色可选
  • 椒江网站建设公司企业网站建设合同书模板
  • 怎么给网站加ico图标怎么把网站横幅做很大
  • 中原郑州网站建设金乡县住房与城乡建设局网站
  • 网址收录网站wordpress安装位置
  • 家教网站建设wordpress改变字体
  • 深圳企业网站制作公司介绍悠悠我心个人网站模板
  • 济宁梵盛科技网站建设建筑工程分包信息网络平台
  • wordpress设置网站主题网站建设合作加盟