简介
- 链上治理
- 提名权益证明 (PoS) 区块链
- 智能合约平台
- 建立 Parity Substrate之上, 使用 WASM (WebAssembly) 运行时。
- 并且能够同时运行 EVM(Solidity)合约和 Rust(Ink!)合约
启动本地Edgeware节点
- 下载源码
git clone https://github.com/edgeware-network/edgeware-node
cd edgeware-node
- 启动
docker-compose -f docker/docker-compose-local.yml up
Starting docker_edgeware_1 ... done
Attaching to docker_edgeware_1
edgeware_1 | 2021-10-20 14:42:54 It isn't safe to expose RPC publicly without a proxy server that filters available set of RPC methods.
edgeware_1 | 2021-10-20 14:42:54 It isn't safe to expose RPC publicly without a proxy server that filters available set of RPC methods.
edgeware_1 | 2021-10-20 14:42:54 Edgeware Node
edgeware_1 | 2021-10-20 14:42:54 ✌️ version 3.3.3-41634fe-x86_64-linux-gnu
edgeware_1 | 2021-10-20 14:42:54 ❤️ by Commonwealth Labs <hello@commonwealth.im>, 2017-2021
edgeware_1 | 2021-10-20 14:42:54 📋 Chain specification: Development
edgeware_1 | 2021-10-20 14:42:54 🏷 Node name: myNode
edgeware_1 | 2021-10-20 14:42:54 👤 Role: AUTHORITY
edgeware_1 | 2021-10-20 14:42:54 💾 Database: RocksDb at /edgeware/.local/share/edgeware/chains/dev/db
edgeware_1 | 2021-10-20 14:42:54 ⛓ Native runtime: edgeware-48 (edgeware-node-48.tx2.au16)
edgeware_1 | 2021-10-20 14:42:54 Using default protocol ID "sup" because none is configured in the chain specs
edgeware_1 | 2021-10-20 14:42:54 🏷 Local node identity is: 12D3KooWJLFV74d6ojyQuZ8WE9NcuDmqA9EokGaR4UYayJLX9ZoF
edgeware_1 | 2021-10-20 14:42:55 📦 Highest known block at #12
edgeware_1 | 2021-10-20 14:42:55 〽️ Prometheus server started at 127.0.0.1:9615
edgeware_1 | 2021-10-20 14:42:55 Listening for new connections on 0.0.0.0:9944.
edgeware_1 | 2021-10-20 14:42:57 Accepted a new tcp connection from 172.18.0.1:55988.
edgeware_1 | 2021-10-20 14:42:59 Accepted a new tcp connection from 172.18.0.1:55992.
- 连接polkadot-js
https://polkadot.js.org/app,配置url
导入开发者账号到metamask
-
配置metamask网络
-
导入私钥
Private Key: 1111111111111111111111111111111111111111111111111111111111111111
Address: 0x19e7e376e7c213b7e7e7e46cc70a5dd086
2. 查看余额
wasm 合约部署
安装工具 ink! 命令行工具
cargo install --git https://github.com/hicommonwealth/cargo-contract cargo-contract --force
安装后使用 cargo contract --help
测试是否安装成功
创建ink! 项目
cargo contract new flipper
cd flipper/
目录结构如下
❯ tree
.
├── Cargo.toml
└── lib.rs
cli会自动生成Flipper合约源码。Flipper 合约只不过是一个布尔值,它通过flip()函数从 true 翻转为 false 。
❯ cat lib.rs
#![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
#[ink::contract]
mod flipper {
/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
#[ink(storage)]
pub struct Flipper {
/// Stores a single `bool` value on the storage.
value: bool,
}
impl Flipper {
/// Constructor that initializes the `bool` value to the given `init_value`.
#[ink(constructor)]
pub fn new(init_value: bool) -> Self {
Self { value: init_value }
}
/// Constructor that initializes the `bool` value to `false`.
///
/// Constructors can delegate to other constructors.
#[ink(constructor)]
pub fn default() -> Self {
Self::new(Default::default())
}
/// A message that can be called on instantiated contracts.
/// This one flips the value of the stored `bool` from `true`
/// to `false` and vice versa.
#[ink(message)]
pub fn flip(&mut self) {
self.value = !self.value;
}
/// Simply returns the current value of our `bool`.
#[ink(message)]
pub fn get(&self) -> bool {
self.value
}
}
/// Unit tests in Rust are normally defined within such a `#[cfg(test)]`
/// module and test functions are marked with a `#[test]` attribute.
/// The below code is technically just normal Rust code.
#[cfg(test)]
mod tests {
/// Imports all the definitions from the outer scope so we can use them here.
use super::*;
/// We test if the default constructor does its job.
#[test]
fn default_works() {
let flipper = Flipper::default();
assert_eq!(flipper.get(), false);
}
/// We test a simple use case of our contract.
#[test]
fn it_works() {
let mut flipper = Flipper::new(false);
assert_eq!(flipper.get(), false);
flipper.flip();
assert_eq!(flipper.get(), true);
}
}
}
测试合约
cargo +nightly test
结果如下
running 2 tests
test flipper::tests::it_works ... ok
test flipper::tests::default_works ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
编译你的合约
cargo +nightly contract build
编译完后 target目录会生成wasm文件
target
└── flipper.wasm
生成合约元数据(abi)
cargo +nightly contract generate-metadata
会在target目录生成metadata.json文件
target
├── flipper.wasm
└── metadata.json
看一下这个文件的结构
{
"metadataVersion": "0.1.0",
"source": {
"hash": "0x5d607d66012d3f9bf50e4832d666027dafbd513dc82876a20a30a4e441a7a1cd",
"language": "ink! 3.0.0-rc2",
"compiler": "rustc 1.58.0-nightly"
},
"contract": {
"name": "flipper",
"version": "0.1.0",
"authors": [
"[your_name] <[your_email]>"
]
},
"spec": {
"constructors": [
{
"args": [
{
"name": "init_value",
"type": {
"displayName": [
"bool"
],
"type": 1
}
}
],
"docs": [
" Constructor that initializes the `bool` value to the given `init_value`."
],
"name": [
"new"
],
"selector": "0xd183512b"
},
{
"args": [],
"docs": [
" Constructor that initializes the `bool` value to `false`.",
"",
" Constructors can delegate to other constructors."
],
"name": [
"default"
],
"selector": "0x6a3712e2"
}
],
"docs": [],
"events": [],
"messages": [
{
"args": [],
"docs": [
" A message that can be called on instantiated contracts.",
" This one flips the value of the stored `bool` from `true`",
" to `false` and vice versa."
],
"mutates": true,
"name": [
"flip"
],
"payable": false,
"returnType": null,
"selector": "0xc096a5f3"
},
{
"args": [],
"docs": [
" Simply returns the current value of our `bool`."
],
"mutates": false,
"name": [
"get"
],
"payable": false,
"returnType": {
"displayName": [
"bool"
],
"type": 1
},
"selector": "0x1e5ca456"
}
]
},
"storage": {
"struct": {
"fields": [
{
"layout": {
"cell": {
"key": "0x0000000000000000000000000000000000000000000000000000000000000000",
"ty": 1
}
},
"name": "value"
}
]
}
},
"types": [
{
"def": {
"primitive": "bool"
}
}
]
}
部署你的合约
-
打开polkadot-js 找到合约tab
-
点击Upload & deploy code ,依次选择
metadata.json
和flipper.wasm
文件,code bundle name
为flipper, 点击next
-
构造函数选择default , 捐赠填写10 gas 填写100000,点击部署
-
点击签名并提交
-
随后列表中将展示你部署好的合约
调用智能合约
回顾一下,我们将 Flipper 合约的初始值设置为false,我们翻动一下,点击exec
点击execute
签名并提交
随后我们将值发生了改变
evm 合约部署
略