惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
小众软件
小众软件
GbyAI
GbyAI
B
Blog RSS Feed
月光博客
月光博客
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
博客园_首页
G
Google Developers Blog

博客园 - 消失的风

富文本编辑器vue2-editor实现全屏功能 使用Mist部署Contract到Rinkeby以太坊网络 技术顾问认知(一) Angularjs-项目搭建 Augularjs-起步 appfuse:Excel导出 Appfuse:添加自定义页面组件 基于JQuery实现的文本框自动填充功能 Appfuse:权限控制 Appfuse:记录操作日志 Appfuse:扩展自己的GenericManager Appfuse:第一张表维护 Appfuse:起步 JAVA实现图片裁剪 Mybatis基于注解的方式访问数据库 敏捷开发与jira之研发管理模式 敏捷开发与jira之阶段工作项概述 敏捷开发与jira之燃烧图 敏捷开发与jira之流程
基于以太坊的Token开发步骤
消失的风 · 2018-03-30 · via 博客园 - 消失的风

Token开发步骤

一、准备工具
1.安装以太坊
brew tap ethereum/ethereum
brew install ethereum
2.node:brew install nodejs
3.安装依赖库:npm install -g ganache-cli web3 solc truffle truffle-contract zeppelin-solidity
4.运行ganache-cli,端口默认是8545
5.配置myetherwallet设置自定义的网络:https://www.myetherwallet.com/
6.安装vs code
7.安装MetaMask插件(Chrome),配置网络同myetherumwallet

二、开发
1.truffle unbox vue-box, 其他的box可以在http://truffleframework.com/boxes/中找到
2.新建自己的Contract,示例代码如下:

pragma solidity ^0.4.18;

import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";

contract FirstToken is StandardToken {
    string public name = "FirstToken"; 
    string public symbol = "FST";
    uint public decimals = 18;
    uint public INITIAL_SUPPLY = 10000 * (10 ** decimals);

    function FirstToken() public {
        balances[msg.sender] = INITIAL_SUPPLY;
    }
}

3.编辑migrations\2_deploy_contracts.js增加自己编写的Contract的部署代码:deployer.deploy(FirstToken);
4.配置项目的truffle.config中的网络,确保端口是8545
5.运行truffle comiple 编译contract
6.运行truffle migrate --reset部署网络
7.新建自己的测试页面,关键代码如下:

<script>
import Web3 from 'web3'
import contract from 'truffle-contract'
import artifacts from '../../build/contracts/FirstToken.json'
const FirstTokenContract = contract(artifacts)

export default {
   name: 'FirstToken',
    data() {
        return {
            web3: null,
            account: null,
            token: null,
            address: '0x554f40f004758c2043992379465a04371ffdd9e1',
            num: 10,
            result: null
        }
    },
    created() {
        if (typeof web3 !== 'undefined') {
            this.web3 = Object.freeze(new Web3(web3.currentProvider))
        } else {
            this.web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"))
        }
        FirstTokenContract.setProvider(this.web3.currentProvider)
        this.account = this.web3.eth.coinbase
        this.web3.eth.defaultAccount = this.web3.eth.coinbase
        FirstTokenContract.defaults({from: this.web3.eth.coinbase})
        FirstTokenContract.deployed().then((instance) => {
            instance.balanceOf(this.account).then((value) => this.token = value)
        });
    },
    methods: {
        send() {
            return FirstTokenContract.deployed()
                .then((instance) => {
                    console.log('from:' + this.account)
                    console.log('to:' + this.address);
                    instance.transfer(this.address, this.num)
                    return instance
                })
                .then((instance) => {
                    instance.balanceOf(this.address).then((value) => this.result = value)
                    instance.balanceOf(this.account).then((value) => this.token = value)
                })
                .catch((e) => {
                    console.error(e)
                })
        },
        query() {
            return FirstTokenContract.deployed()
                .then((instance) => {
                    instance.balanceOf(this.address).then((value) => this.result = value)
                })
                .catch((e) => {
                    console.error(e)
                })
        },
    }
}
</script>

8.运行send方法的时候注意要在MetaMask中点击提交才会真正执行

相关网站:
1.Truffle: http://truffleframework.com/
2.MyEtherWallet: https://www.myetherwallet.com
3.Solidity: http://solidity.readthedocs.io/en/v0.4.21/
4.Zeppelin: https://github.com/OpenZeppelin/zeppelin-solidity
5.MetaMask:https://metamask.io/

编外网站:
1.代币的市值:www.coinmarketcap.com
2.Rinkeby测试网的地址:https://www.rinkeby.io