以太坊钱包 ERC20 Token 代币 Node 封装接口

Netkiller Blockchain 手札

Mr. Neo Chan, 陈景峯(BG7NYT)

中国广东省深圳市龙华新区民治街道溪山美地 518131 +86 13113668890 <netkiller@msn.com>

文档始创于2018-02-10

版权 © 2018 Netkiller(Neo Chan). All rights reserved.

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

内容摘要

这一部关于区块链开发及运维的电子书。

为什么会写区块链电子书?因为2018年是区块链年,区块链是一个风口,前几个风口我都错过了。例如web2.0, 云, 大数据等等,都从身旁擦肩而过。所以我要抓住这次。

这本电子书是否会出版(纸质图书)? 不会,因为互联网技术更迭太快,纸质书籍的内容无法实时更新,一本书动辄百元,很快就成为垃圾,你会发现目前市面的上区块链书籍至少是一年前写的,内容已经过时,很多例子无法正确运行。所以我不会出版,电子书的内容会追逐技术发展,及时跟进软件版本的升级,做到内容最新,至少是主流。

这本电子书与其他区块链书籍有什么不同?市面上大部分区块链书籍都是用2/3去讲区块链原理,只要不到 1/3 的干货,干货不够理论来凑,通篇将理论或是大谈特谈区块链行业,这些内容更多是头脑风暴,展望区块链,均无法落地实施。本书与那些书籍完全不同,不讲理论和原理,面向应用落地,注重例子,均是干货。

写作原则,无法落地的项目作者绝对不会写。凡是写入电子的内容均具备可操作,可落地。

电子书更新频率?每天都会有新内容加入,更新频率最迟不会超过一周,更新内容请关注 https://github.com/netkiller/netkiller.github.io/commits/master

本文采用碎片化写作,原文会不定期更新,请尽量阅读原文 http://www.netkiller.cn/blockchain/index.html

您的打赏是我的写作动力:http://www.netkiller.cn/blockchain/donations.html

接受 ETH 打赏:0x3e827461Cc53ed7c75A29187CfF39629FCAE3661

Account

List

功能:获取账号列表
请求:GET
地址: http://localhost:8000/api/account/list.json
演示:
neo@MacBook-Pro ~/ethereum/web3.example % curl http://localhost:8000/api/account/list.json
{"status":true,"code":0,"data":{"accounts":["0x8dA0bB9Ee3a7d85763d1B5320D8c0f859F0438ff","0xa745D295d2E35B16b2F41da48D9883CcE3c609a7","0x7cB22cb3d8a58ade32f3BfC3E6a4dEd1efAEe080","0x8efB99Ec55bCfBE2CFe47918f2d9E55FA732111f","0xc28Ec50bFeD8E4B88780e910a802dA8Fa347CCad","0xF0688330101d53BD0C6ede2Ef04d33c2010e9a5d","0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343"]}}

New Account

功能:创建以太坊账号
请求:POST
发送数据: password=123456  
地址:http://localhost:8000/api/account/new.json
演示:
neo@MacBook-Pro ~/ethereum/web3.example % curl -XPOST -d 'password=123456' http://localhost:8000/api/account/new.json
{"status":true,"code":0,"data":{"account":"0xbd38Cb8a53d1c051faF0F4E186f9ef2bBaEb308A"}}

Ethereum balance ETH

功能:获取指定账号 ETH 数量
请求:GET
参数:address=0x3FBB5e96c9a643450B0e76c5c2122048FC733fC6
地址:http://localhost:8000/api/balance.json
演示:
% curl "http://localhost:8000/api/balance.json?address=0x3FBB5e96c9a643450B0e76c5c2122048FC733fC6"
{"status":true,"code":0,"data":{"account":"0x3FBB5e96c9a643450B0e76c5c2122048FC733fC6","balance":"0"}}%

Ethereum balance spending

功能:计算可以支配的最大 ETH 金额,balance - fee
curl "http://localhost:8000/api/balance/spending.json?address=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343"
neo@MacBook-Pro ~/ethereum/web3.example % curl "http://localhost:8000/api/balance/spending.json?address=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343"
{"status":true,"code":0,"data":{"account":"0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343","balance":"98.770587102","wei":"98770587102000000000","price":"18000000000","gas":21000,"cost":378000000000000}}

Transfer

ETH

功能:ETH 转账
请求:POST
参数:
	from=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343
	to=0xc28Ec50bFeD8E4B88780e910a802dA8Fa347CCad
	amount=1000
	password=12345678
地址:
	http://localhost:8000/api/transfer.json
演示:
% curl -XPOST -d 'from=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343&to=0xc28Ec50bFeD8E4B88780e910a802dA8Fa347CCad&amount=100&password=12345678' http://localhost:8000/api/transfer.json
{"status":true,"code":0,"data":{"hash":"0x81ba2f2a79fb819c1cac544536e0a4df2d8417b64f3781299213a174a154d4de"}}% 
curl -XPOST -d 'from=0x8dA0bB9Ee3a7d85763d1B5320D8c0f859F0438ff&to=0xc28Ec50bFeD8E4B88780e910a802dA8Fa347CCad&amount=1000000000&password=12345678' http://localhost:8000/api/transfer.json

ETH Sign Transaction

功能:私钥签名转账适用于 HDWallet
请求:POST
参数:
	from=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343
	to=0xc28Ec50bFeD8E4B88780e910a802dA8Fa347CCad
	amount=1000
	key=1b6e3fa7b65e324ee1e6be9633bc07414b30f4eccfdcc9b2601
地址:
	http://localhost:8000/api/transfer/sign.json
演示:
% curl -XPOST -d 'from=0x7cB22cb3d8a58ade32f3BfC3E6a4dEd1efAEe080&to=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343&amount=5&key=1b6e3fa7b65e324ee1e6be963e075c16397a4b3bc07414b30f4eccfdcc9b2601' http://localhost:8000/api/transfer/sign.json

Token

Token balance

功能:获取指定代币余额
请求:GET
参数:address=0x3FBB5e96c9a643450B0e76c5c2122048FC733fC6
    symbol=EOS
地址:http://localhost:8000/api/balance/token.json
演示:
neo@MacBook-Pro ~/ethereum/web3.example % curl "http://localhost:8000/api/balance/token.json?address=0xa745D295d2E35B16b2F41da48D9883CcE3c609a7&symbol=ADC"
{"status":true,"code":0,"data":{"account":"0xa745D295d2E35B16b2F41da48D9883CcE3c609a7","balance":"100.000000000000000000","symbol":"ADC","decimals":"18"}}
curl "http://localhost:8000/api/balance/token.json?address=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343&symbol=TT6"

Token transfer

功能:代币转账
请求:POST
参数:
	from=0x3FBB5e96c9a643450B0e76c5c2122048FC733fC6
	to=0xC41c6579ec90dA887FbbeE99db96f139A78f7E87
	amount=100
	symbol=ADC
	password=12345678
地址:
	http://localhost:8000/api/transfer/token.json
演示:
% curl -XPOST -d 'from=0x7cB22cb3d8a58ade32f3BfC3E6a4dEd1efAEe080&to=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343&amount=100&symbol=ADC&password=12345678' http://localhost:8000/api/transfer/token.json
neo@MacBook-Pro ~/ethereum/web3.example % curl -XPOST -d 'from=0x7cB22cb3d8a58ade32f3BfC3E6a4dEd1efAEe080&to=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343&amount=100&symbol=ADC&password=12345678' http://localhost:8000/api/transfer/token.json
{"status":true,"code":0,"data":{"txhash":{"blockHash":"0x1ba62b0692b08e13334a163f0446ceba64bf6eeecb4cacef9a2a02b470a1e981","blockNumber":7878,"contractAddress":null,"cumulativeGasUsed":38131,"from":"0x7cb22cb3d8a58ade32f3bfc3e6a4ded1efaee080","gasUsed":38131,"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000010000000000000000000000000000000000000000008000000000000000080000000000000000000000420000200000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000010000000000000000000080000000000000000000000000000000000000000000000000000000000001000","root":"0x2d0d9c01243726ffdee3bc2a928497f8b7508612220cefc647249498989b89dc","to":"0x8d33e4bd2516a96453b730016d6b09cbc5e0d488","transactionHash":"0x4d664612680eebb56efe9607f48af20afb8a7ff31f9c96e509c9f4bc80e46914","transactionIndex":0,"events":{"Transfer":{"address":"0x8d33E4Bd2516a96453b730016D6B09Cbc5e0d488","blockNumber":7878,"transactionHash":"0x4d664612680eebb56efe9607f48af20afb8a7ff31f9c96e509c9f4bc80e46914","transactionIndex":0,"blockHash":"0x1ba62b0692b08e13334a163f0446ceba64bf6eeecb4cacef9a2a02b470a1e981","logIndex":0,"removed":false,"id":"log_f935a529","returnValues":{"0":"0x7cB22cb3d8a58ade32f3BfC3E6a4dEd1efAEe080","1":"0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343","2":"100000000000000000000","from":"0x7cB22cb3d8a58ade32f3BfC3E6a4dEd1efAEe080","to":"0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343","value":"100000000000000000000"},"event":"Transfer","signature":"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","raw":{"data":"0x0000000000000000000000000000000000000000000000056bc75e2d63100000","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000007cb22cb3d8a58ade32f3bfc3e6a4ded1efaee080","0x000000000000000000000000fbfe02e82d22737ebbbadc1e07a47f6e3f226343"]}}}}}}

Token Sign Transaction

功能:私钥签名代币转账
请求:POST
参数:
	from=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343
	to=0xc28Ec50bFeD8E4B88780e910a802dA8Fa347CCad
	amount=1000
	symbol=TT6
	key=1b6e3fa7b65e324ee1e6be963e075c16397a4b3bc07414b30f4ece075c16397a4bcfdcc9b2601
地址:
	http://localhost:8000/api/transfer/sign.json
演示:
neo@MacBook-Pro ~/ethereum/web3.example % curl -XPOST -d 'from=0x7cB22cb3d8a58ade32f3BfC3E6a4dEd1efAEe080&to=0xfbFe02E82d22737eBBBaDc1E07a47F6e3F226343&amount=5&symbol=ADC&key=1b6e3fa7b65e324ee1e6bbc07414b30f4eccfdce963e075c16397a4b3c9b2601' http://localhost:8000/api/transfer/token/sign.json
{"status":true,"code":0,"data":{"txhash":{"blockHash":"0xd1c24f1a323454465c0ededd7a64b3ccbd46463bbae2fb5022471507a5bcb78c","blockNumber":7803,"contractAddress":null,"cumulativeGasUsed":38067,"from":"0x7cb22cb3d8a58ade32f3bfc3e6a4ded1efaee080","gasUsed":38067,"logs":[{"address":"0x8d33E4Bd2516a96453b730016D6B09Cbc5e0d488","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000007cb22cb3d8a58ade32f3bfc3e6a4ded1efaee080","0x000000000000000000000000fbfe02e82d22737ebbbadc1e07a47f6e3f226343"],"data":"0x0000000000000000000000000000000000000000000000004563918244f40000","blockNumber":7803,"transactionHash":"0x263890e247c3f57dde560c6faa29b116732722730b5f3b296394065c8a27a54e","transactionIndex":0,"blockHash":"0xd1c24f1a323454465c0ededd7a64b3ccbd46463bbae2fb5022471507a5bcb78c","logIndex":0,"removed":false,"id":"log_97902585"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000010000000000000000000000000000000000000000008000000000000000080000000000000000000000420000200000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000010000000000000000000080000000000000000000000000000000000000000000000000000000000001000","root":"0xb0de26fada4c6150c2b090ebadfcdf0801a67d4b5d52a9d4e03369bc1e2a0d23","to":"0x8d33e4bd2516a96453b730016d6b09cbc5e0d488","transactionHash":"0x263890e247c3f57dde560c6faa29b116732722730b5f3b296394065c8a27a54e","transactionIndex":0}}}

Mnemonic

功能:获得 HDwallet 钱包助记词
neo@MacBook-Pro ~/ethereum/web3.example % curl http://localhost:8000/api/account/mnemonic.json 
{"status":true,"code":0,"data":{"mnemonic":"mobile organ quit strong rude stick ordinary another daughter top salmon help","ethereum":{"address":"0xf9b22d9ccA01c2f03b98dadB7d15E84962A53E6b","privateKey":"0x2D3Eec673972e065724eEDB43D125742F4b3807A87DAf7C50186C64df8d1b4a2"},"bitcoin":{"address":"1CNQAn1d1iZmnuBUAQ55GmzufikPrbuvsZ","privateKey":"L4qyDyXAjZ9EmQrSatiNrPq75JX1t6WLbuGcgQzXfykGyKaT2gXB"}}}

代码有偿提供,接受微信,支付宝,ETH,同时赠送等额 NBRC (Netkiller 读者币)请加作者微信或QQ。

微信/电话:13113668890

QQ: 13721218

原创声明,本文系作者授权云+社区发表,未经许可,不得转载。

如有侵权,请联系 yunjia_community@tencent.com 删除。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏腾讯开源的专栏

【开业大吉】ncnn君是大厨师

ncnn 君是做什么的? ncnn君是大厨师(框架),会做很多菜,但凡涉及人工智能的菜(应)肴(用)都可以做,比如类似于 faceu 的贴猫耳贴爱心,比如自动识...

3746
来自专栏申龙斌的程序人生

门罗币XMR再次分叉了

2018年10月18日,门罗币(Monero)再次进行了硬分叉,如果你正在用显卡进行XMR挖矿,请注意更新软件版本和相关参数。

2141
来自专栏申龙斌的程序人生

云币网及KYC【区块链生存训练】

李笑来在7月5日发布了Press.One即将 ICO 的消息,大批小白开始在云币网注册开户,我的“区块链生存训练”饭团也在一夜之间加入了40多人。有位新人在饭团...

3558
来自专栏极客编程

共识算法比较Tendermint的BFT与EOS的dPoS

这项技术深入研究由Chjango Unchained编写。本文比较了不同的共识系统,它们为EOS和Tendermint提供了关于每种基础技术以及它们有什么样的独...

1122
来自专栏FreeBuf

AlphaBay是怎么垮掉的?解密全球最大黑市AlphaBay被查封全过程

又一大暗网市场AlphaBay倒下了,而更加悲剧的是,该网站背后的主谋竟在监狱中自杀了…据说当时警方总共收缴了四辆兰博基尼和三套房产,还真是有钱也没命花啊! ?...

2785
来自专栏安恒信息

假WiFi15分钟可盗取信息 网银被盗6万剩500块

近日,@央视新闻等多家权威媒体官方微博曝光,称一种利用假冒商场、快餐店的免费WiFi的骗术正在流行,通过这种方法,用户手机中的网银可以很轻易地...

3607
来自专栏程序员宝库

1 程序员 编写银行后台程序,盗窃 700 余万

利用职务便利,覃某在华夏银行总行核心系统内植入计算机病毒程序,使跨行ATM机取款交易不能计入账户,之后成功取款717.9万元非法占为己有。今天上午,覃某因涉嫌职...

2964
来自专栏FreeBuf

不懂DDoS攻击,不敢去卖煎饼

事件回放 据网友@大咕咕咕鸡爆料: “楼下的煎饼摊子o2o了!只接受微信在线交流,现场拒绝讲话,用一个纸箱子把摊子包起来了!就露一个小洞。买煎饼的在微信订好,提...

2407
来自专栏我是攻城师

男子接陌生短信回“你是谁” 银行卡遭盗刷12次

3426
来自专栏数据和云

数据库流行度6月排行榜:Oracle飙升MySQL止跌回升

六一儿童节,虽然是大家快乐的假期,但是也宣告了2018年进入中场。在DB-Engines的6月排行榜上,不同的数据库产品竞争也进入中场。先预祝大家中场收获满满!...

1404

扫码关注云+社区