- 第 1 章 区块链
- 1.2. 什么是智能合约?
- 1.3. 我们应该怎么做?
- 1.4. 如何学习区块链
- 1.5. 币圈与链圈
- 1.6. 区块链能做什么
- 1.7. 区块链不能解决的问题
- 1.8. 理解去中心化
- 1.9. 理解不可撰改
- 1.10. 理解分布式记账
- 1.11. 安全问题
- 1.12. 区块链落地面临的问题
- 1.13. 区块链未来
- 1.14. 区块链的六层模型
- 1.15. 共识机制
- 1.16. SHA-256
- 1.17. Base58编码
- 1.18. Merkle
- 1.19. BIP39协议:使用助记词生成确定性钱包
- 1.20. Ethereum vs Hypterledger Fabic vs EOS 对比
- 1.21. 区块链探索
- 第 2 章 以太坊
- 第 3 章 以太坊私链入门
- 第 4 章 以太坊网络
- 第 5 章 geth v1.8.16 命令详解
- 第 6 章 Wallet
- 第 7 章 Token
- 第 8 章 智能合约语言 Solidity v0.5.0
- 8.2. solc 命令
- 8.3. 智能合约入门演示
- 8.4. Helloworld Example
- 8.5. 数据类型
- 8.6. 单位
- 8.7. 变量
- 8.8. 函数
- 8.9. 事件
- 8.10. 面向对象编程
- 8.11. 合约调用
- 8.12. 合约接收 ETH
- 8.13. 合约中实例化一个接口
- 8.14. 合约中实例化另一个合约
- 8.15. Solidity 安全问题
- 8.16. solidity example
- 8.17. Zeppelin Solidity - OpenZeppelin is a library for writing secure Smart Contracts on Ethereum.
- 第 9 章 Truffle v4.1.8 开发框架
- 第 10 章 web3.js - 1.0.0
- 第 11 章 web3j v3.4.0 - Jave Client
- 11.2. 启动以太坊
- 11.3. Maven pom.xml 文件
- 11.4. Java 与 Solidity 数据类型映射关系
- 11.5. 常量
- 11.6. 连接到服务器获取版本号
- 11.7. 获得以太坊状态信息
- 11.8. 单位转换
- 11.9. 账号管理
- 11.10. Credentials
- 11.11. 交易
- 11.12. 钱包
- 11.13. 智能合约
- 11.14. ERC20合约
- 11.15. Infura
- 11.16. 助记词
- 11.17. 过滤器 (Filter)
- 11.18. Subscription
- 11.19. 解锁账号
- 11.20. IBAN (International Bank Account Number)
- 11.21. Springboot with Ethereum (web3j)
- 第 12 章 web3.py - A python interface for interacting with the Ethereum blockchain and ecosystem.
- 第 14 章 Ethereum Developer APIs
- 第 15 章 infura
- 第 16 章 以太坊案例
- 第 17 章 FAQ
- 17.3. Error: authentication needed: password or unlock
- 17.4. 新增节点后不生效
- 17.5. Unhandled rejection Error: Returned error: The method personal_unlockAccount does not exist/is not available
- 17.6. Error: exceeds block gas limit
- 17.7. Migrations.sol:11:3: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(…) { … }" instead.
- 17.8. Exception in thread "main" rx.exceptions.OnErrorNotImplementedException: Invalid response received: okhttp3.internal.http.RealResponseBody@6c25e6c4
- 17.9. 旧版本 Remix(browser-solidity) 本地安装
- 第 18 章 Hyperledger Fabric v2.0.0
- 第 19 章 Hyperledger Fabric 运维
- 第 20 章 Chaincode 链码(智能合约)
- 第 21 章 Hyperledger Fabric Client SDK for Node.js
- 第 22 章 fabric-sdk-java
- 第 24 章 已知 Hyperledger 落地案例
- 第 25 章 Fabric Command
- 第 26 章 Fabric FAQ
- 第 27 章 IPFS(InterPlanetary File System,星际文件系统)
- 第 28 章 IPFS 命令
- 第 29 章 IPFS WebUI
- 第 30 章 IPFS 集群配置
- 第 31 章 IPFS API
- 第 32 章 IPFS Faq
- 第 33 章 EOS
- 第 34 章 EOS 安装
- 第 35 章 CLEOS
- 第 36 章 智能合约开发
- 第 37 章 EOS Dapp 开发
- 第 38 章 FAQ
- 第 39 章 BaaS (Blockchain as a Service) 平台
- 第 40 章 BitCoin
- 第 41 章 其他区块链相关
- 附录 1. 附录
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
5.11. 运行智能合约
5.11. 运行智能合约
pragma solidity ^0.4.18; contract Netkiller { string name; int num; function Netkiller() public{ name = "default"; num = 1; } function setName(string _name) public{ name = _name; } function getName() public view returns(string){ return name; } function setNum(int n) public{ num = n; } function addNum(int m) public view returns(int res){ res = m + num; } }
solc --bin --abi --optimize -o output Netkiller.sol
var abi = JSON.parse('内容来自 Netkiller.abi')
var bytecode = "0x"+"内容来自 Netkiller.bin"
var abi = JSON.parse('[{"constant":true,"inputs":[],"name":"getName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"n","type":"int256"}],"name":"setNum","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"string"}],"name":"setName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"m","type":"int256"}],"name":"addNum","outputs":[{"name":"res","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]'); var bytecode = "0x6060604052341561000f57600080fd5b6040805190810160405280600781526020017f64656661756c74000000000000000000000000000000000000000000000000008152506000908051906020019061005a929190610067565b506001808190555061010c565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a857805160ff19168380011785556100d6565b828001600101855582156100d6579182015b828111156100d55782518255916020019190600101906100ba565b5b5090506100e391906100e7565b5090565b61010991905b808211156101055760008160009055506001016100ed565b5090565b90565b61036b8061011b6000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806317d7de7c146100675780636a5aa5ec146100f5578063c47f002714610118578063cc13962a14610175575b600080fd5b341561007257600080fd5b61007a6101ac565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100ba57808201518184015260208101905061009f565b50505050905090810190601f1680156100e75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561010057600080fd5b6101166004808035906020019091905050610254565b005b341561012357600080fd5b610173600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190505061025e565b005b341561018057600080fd5b6101966004808035906020019091905050610278565b6040518082815260200191505060405180910390f35b6101b4610286565b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b8060018190555050565b806000908051906020019061027492919061029a565b5050565b600060015482019050919050565b602060405190810160405280600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106102db57805160ff1916838001178555610309565b82800160010185558215610309579182015b828111156103085782518255916020019190600101906102ed565b5b509050610316919061031a565b5090565b61033c91905b80821115610338576000816000905550600101610320565b5090565b905600a165627a7a7230582002b42864089a104d4d80ba0190924e09e15f3c0d0aa107463f49e2689e159b480029"; var gas = web3.eth.estimateGas({data: bytecode}) var deploy = {from:eth.coinbase, data: bytecode, gas: gas}; var address = eth.coinbase; personal.unlockAccount(eth.accounts[0],"chen1980") var mycontract = web3.eth.contract(abi) var instance = mycontract.new({from:eth.coinbase, data:bytecode, gas:300000}, function(e, contract){ if(!e) { if(!contract.address) { console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined..."); } else { console.log("Contract mined! Address: " + contract.address); console.log(contract); } } }); var test = mycontract.at(eth.coinbase) test.addNum(567);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论