solidity编写智能合约HelloWorld Demo

使用solidity前你需要 安装matemask插件创建钱包账户 (这里不做具体介绍)

第一步 打开在线编辑器 remix

http://remix.ethereum.org

第二步 新建.sol文件

在左侧browser 中 新增.sol 名为Demo.sol

第三步 编写solidity合约代码
pragma solidity ^0.4.24;
//声明合约
contract Demo{
    function hello() pure returns(string){
        return "hello worldxxxx!";
    }
}
第四步 Compile 编译合约代码

在右侧Compile 区,选择以上合约代码编译对应的版本(version)
选择 :0.4.24+commit.e67f0147
点击 Start to compile 进行编译

第五步 Run 部署及执行合约代码

右侧Run区 选择Demo这个合约 然后 deploy 进行部署
部署后你会在日志区域看到creation of Demo pending…
后面接着打印输出 debug 你能看到这个部署合约的相关地址信息
然后 Deployed Contracts(已部署合同)中会看到 Demo at 0xeda…fd723 (blockchain)
点开你会看到 hello 方法 点击执行 即可看到效果

很高兴回答您的问题!Langchain是一种基于区块链技术的多语言智能合约编写和执行平台,它可以帮助开发人员更加方便地编写和执行跨语言智能合约。以下是一个简单的Langchain示例: 假设我们有两个合约,一个用Solidity编写,一个用Python编写。我们可以使用Langchain将它们连接起来,并在两种语言之间进行调用。 Solidity合约: ``` contract HelloWorld { string message; constructor() public { message = "Hello, World!"; } function getMessage() public view returns (string memory) { return message; } } ``` Python合约: ``` from langchain_runtime import LangchainRuntime class HelloWorld: def __init__(self): self.message = "Hello, World!" def get_message(self): return self.message langchain_runtime = LangchainRuntime() langchain_runtime.export(HelloWorld) ``` 在Langchain中,我们可以使用以下代码将这两个合约连接起来: ``` from langchain_runtime import LangchainRuntime langchain_runtime = LangchainRuntime() # 部署Solidity合约 solidity_contract_address = langchain_runtime.deploy_contract('solidity', ''' contract HelloWorld { string message; constructor() public { message = "Hello, World!"; } function getMessage() public view returns (string memory) { return message; } } ''') # 部署Python合约 python_contract_address = langchain_runtime.deploy_contract('python', ''' from langchain_runtime import LangchainRuntime class HelloWorld: def __init__(self): self.message = "Hello, World!" def get_message(self): return self.message langchain_runtime = LangchainRuntime() langchain_runtime.export(HelloWorld) ''') # 在两个合约之间进行调用 solidity_contract = langchain_runtime.contract(solidity_contract_address) python_contract = langchain_runtime.contract(python_contract_address) print(solidity_contract.call('getMessage')) # 输出:Hello, World! print(python_contract.call('get_message')) # 输出:Hello, World! ``` 以上就是一个简单的Langchain示例,它展示了如何在多种语言之间使用Langchain编写和执行智能合约
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值