完整版ubuntu上搭建私链,编写智能合约,实现智能合约交互
捣鼓了几天总算是把智能合约部署到自己的ubuntu上,并用node.js进行调用协议,每笔交易用自己的token,可以进行必要时间进行追溯,完整使用区块链,由于solidity更新太快,很多交易的代码都必须改一些才能进行编译,好了,不好这么多这个了。
1、首先你需要拥有一台ubuntu服务器,我这里买的是阿里云的,配置问题,我提醒下,我买的8核16G内存的,挖矿还是比较牛的。 开始: 备选方案1 - 使用混编进行编译,然后复制粘贴进行部署使用https://ethereum.github.io/browser-solidity中的混音: 从Remix页面复制Web3部署说明: var untitled_testContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}]);var untitled_test = untitled_testContract.new( {
from: web3.eth.accounts[0],data: '0x60606040523415600b57fe5b5b607b6000819055505b5b608f806100246000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633fa4f24514603a575bfe5b3415604157fe5b6047605d565b6040518082815260200191505060405180910390f35b600054815600a165627a7a72305820a4fac284b98d43538f802082b0db8c67ddd6d72df4e8d9fbccb4cec0e52ea0df0029',gas: '4700000' }, function (e, contract){
console.log(e, contract); if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); } })
并将其粘贴到 > personal.unlockAccount(eth.accounts[0], "{top secret password}");true> var untitled_testContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}]);"0xe22dc29e3e05d3206d9636ae7cba87a2827e7b3ef28c6e8e6d2ad49a14ba3ce9"var untitled_test = untitled_testContract.new( {
from: web3.eth.accounts[0], data: '0x60606040523415600b57fe5b5b607b6000819055505b5b608f806100246000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633fa4f24514603a575bfe5b3415604157fe5b6047605d565b6040518082815260200191505060405180910390f35b600054815600a165627a7a72305820a4fac284b98d43538f802082b0db8c67ddd6d72df4e8d9fbccb4cec0e52ea0df0029',gas: '4700000' }, function (e, contract){
console.log(e, contract); if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); } })
方案2 - 使用Solidity编译器(Linux和OS / X,也许Windows使用Cygwin)$ more Test.sol pragma solidity ^0.4.8;contract Test {
uint256 public value; function Test() {
value = 123; }}
以.json格式编译Test.sol,将数据分配给JavaScript变量并将输出发送到文件中: $ echo
|
整版ubuntu上搭建私链,编写智能合约,实现智能合约交互
最新推荐文章于 2023-08-14 18:14:36 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)