区块链开发(三)以太坊智能合约部署和使用

Remix是以太坊提供的一个开发Solidity智能合约的网络版开发软件。合约的开发者在Remix里提供的JavaScript虚拟机上开发,调试好合约后,可以发布到以太坊,或者任何支持Solidity智能合约的区块链上。
首先在Remix 新建一个Message.sol

pragma solidity^0.4.20;
contract Message{
    string msg;
    function setMsg(string _msg) public {
        msg=_msg;
    }
    function getMsg() public view returns(string){
        return msg;
    }
}

Message.sol

然后进入此前创建的私有链目录

cuiran@cuiran:~/ethereum$     cd data0/
cuiran@cuiran:~/ethereum/data0$     ls
geth     history  keystore log.txt
cuiran@cuiran:~/ethereum/data0$     geth --datadir . --networkid 4224 --rpc --rpcport 8545 --port 30303 --rpccorsdomain="*" -rpcapi eth,web3,personal,net console 2> log.txt
Welcome to the Geth JavaScript console!

instance: Geth/v1.7.3-stable/darwin-amd64/go1.9.3
coinbase: 0xb258e5b1b30215b112881c13f22ab5a47a624b81
at block: 79 (Mon, 09 Jul 2018 16:20:57 CST)
 datadir: /Users/cuiran/ethereum/data0
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> eth.accounts
["0xb258e5b1b30215b112881c13f22ab5a47a624b81", "0xf417953e3b736a68cf7c60f89f459a28d25880da"]
> personal.unlockAccount("0xb258e5b1b30215b112881c13f22ab5a47a624b81");//解锁账号
Unlock account 0xb258e5b1b30215b112881c13f22ab5a47a624b81
Passphrase:
> eth.sendTransaction({from :user1,to:user2,value:web3.toWei(3,"ether")})
"0x92251d069cf4e6f740c5315003819bb021e533e39bcd563eae8cb091363a4e26"
> miner.start();
null
> miner.stop();
true
>

然后在remix里面deploy发布
就会出现
测试
在setMsg里面输入”hello world”
点击getMsg 会返回hello world

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cuiran

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值