博客
关于我
[区块链笔记10] remix部署合约并连接Ganache 前端web3与智能合约交互
阅读量:329 次
发布时间:2019-03-04

本文共 904 字,大约阅读时间需要 3 分钟。

开启Ganache,搭建好本地的测试链


ganache链接到metamask

要注意这个搭建过程是把ganache链接到metamask而不是连接到remix

具体来说就是ganache链接到metamask上,然后remix通过injected web3的方式又把metamask的账户链接remix上


remix里的run设置里改成injected web3,表示用metamask注入的web3


remix里编辑简单的智能合约并部署

pragma solidity ^0.4.23;contract InfoContract {       string name;    uint age;    function setInfo(string _name, uint _age) public {           name = _name;        age = _age;    }    function getInfo() public view returns (string, uint) {           return (name, age);    }}

把编译后的abi复制一下到infocontract_abi.js文件里

文件内容var infoContractABI = 复制的json格式的abi


编辑index.css

body {   	background-color: #F0F0F0;}#info {   	padding: 20px;	background-color: #FFF;}#button {   	width: 100px;}

前端代码

	
First Dapp demo

First Dapp demo

然后运行apache服务器。

访问页面就会显示合约的状态,也可以通过表单来修改合约的状态,但是要付gas。

在这里插入图片描述

转载地址:http://uknh.baihongyu.com/

你可能感兴趣的文章
Nginx+Keepalived+LVS集群实战
查看>>
Nginx+Keepalived实现简单版高可用主备切换
查看>>
nginx+mysql+redis+mongdb+rabbitmq 自动化部署脚本
查看>>
nginx+php的搭建
查看>>
nginx+tomcat+memcached
查看>>
Nginx+Tomcat实现动静分离
查看>>
nginx+Tomcat性能监控
查看>>
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
Nginx、HAProxy、LVS
查看>>
Nginx下配置codeigniter框架方法
查看>>
Nginx中使用expires指令实现配置浏览器缓存
查看>>