Eosplayer是eosjs的绑定层,它基于eosjs并为应用程序层提供了更好的可用性。它既可以在node.js服务器上使用,也可以在已经安装了Scatter的浏览器或Dapp钱包中使用。
frontd releases : https://github.com/bagaking/eosplayer/releases
演示地址:http://eosplayer.kihand.com/#/
Eosplayer是eosjs的绑定层,它基于eosjs并为应用程序层提供了更好的可用性。它既可以在node.js服务器上使用,也可以在已经安装了Scatter的浏览器或Dapp钱包中使用。
frontd releases : https://github.com/bagaking/eosplayer/releases
演示地址:http://eosplayer.kihand.com/#/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../libs/web3.js_v1.0.0-beta.35/web3.min.js"></script>
</head>
<body>
<h1>Send ERC20 Token</h1>
<h2>Notes</h2>
<ul>
<li>Use MetaMask</li>
<li>To check ERC20 balance, use <a href="../getERC20TokenBalance/" target="_blank">getERC20TokenBalance</a></li>
</ul>
<h2>Token Address</h2>
<input type="text" id="token-address" size="80" oninput="onAddressChange()"></input>
<p>e.g. 0x2A65D41dbC6E8925bD9253abfAdaFab98eA53E34</p>
<h2>Recipients Address</h2>
<input type="text" id="to-address" size="80"></input>
<p>e.g. 0x8Df70546681657D6FFE227aB51662e5b6e831B7A</p>
<h2>Decimals</h2>
<input type="number" id="decimals" size="40" readonly></input>
<h2>Amount</h2>
<input type="number" id="amount" size="40"></input>
<div><button id="send" onclick="send()">Send ERC20 Token</button></div>
<h2>Result</h2>
<span id="result"></span>
<script>
var web3js;
var account;
function getERC20TokenBalance(tokenAddress, walletAddress, callback) {
let minABI = [
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"type":"function"},
{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"type":"function"}
];
let contract = new web3js.eth.Contract(minABI, tokenAddress);
contract.methods.balanceOf(walletAddress).call((error, balance) => {
contract.methods.decimals().call((error, decimals) => {
console.log(balance);
console.log(decimals);
balance = balance / (10**decimals);
callback(balance);
});
});
}
function getERC20TokenContract(tokenAddress) {
let minABI = [
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"type":"function"},
{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"type":"function"},
{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"type":"function"}
];
return new web3js.eth.Contract(minABI, tokenAddress);
}
function getERC20TokenDecimals(callback) {
window.tokenContract.methods.decimals().call((error, decimals) => {
callback(decimals);
});
}
function onAddressChange(e) {
let tokenAddress = document.getElementById('token-address').value;
if(tokenAddress != "") {
window.tokenContract = getERC20TokenContract(tokenAddress);
getERC20TokenDecimals((decimals) => {
document.getElementById('decimals').value = decimals;
});
}
}
function transferERC20Token(toAddress, value, callback) {
window.tokenContract.methods.transfer(toAddress, value).send({from: account})
.on('transactionHash', function(hash){
callback(hash);
});
}
function send() {
var toAddress = document.getElementById('to-address').value;
var decimals = web3js.utils.toBN(document.getElementById('decimals').value);
var amount = web3js.utils.toBN(document.getElementById('amount').value);
var sendValue = amount.mul(web3js.utils.toBN(10).pow(decimals));
console.log(sendValue.toString());
transferERC20Token(toAddress, sendValue, (txHash) => {
document.getElementById('result').innerText = txHash;
});
}
window.onload = function() {
web3js = new Web3(Web3.givenProvider);
console.log(web3js.version);
var accountInterval = setInterval(function() {
web3js.eth.getAccounts((error, address) => {
if (address[0] !== account) {
account = address[0];
console.log(account);
}
});
}, 300);
}
</script>
</body>
</html>
https://github.com/piyolab/sushiether/commit/e35e949b5d898d357f9bd1d4e3f35b679974f192
为了继续深入研究Fabric的加密通道逻辑,找了一个现成的例子,并修正了一个新手部署可能遇到的问题,
修正的主要点是
fabric-samples
路径,OS: Ubuntu 18.04
Fabric: release-1.4
Go: go1.14.4 linux/amd64
Docker: 19.03.11
gitee: https://gitee.com/BCSkill/fcc
git clone https://gitee.com/BCSkill/fcc.git
细节的话可以参考《fabric-samples 部署测试》,我们这里不做详细描述,直接运行封装好的脚本
./1-1.hy-sample.sh
大概过程中会分为几步,
fabric-samples
到当前源码目录fabric
二进制文件,并解压到 fabric-samples/bin
,记得将此目录添加到环境变量./1-2.startNetwork.sh
成功后输出========= All GOOD, BYFN execution completed ===========
./2.addOrg3.sh
完成后,结果显示========= Org3 is now halfway onto your first network =========
./3-1.installNetcon.sh #合约:网签合同备案
./3-2.installEstateBook.sh #合约:不动产权证书
./3-3.installEstateTax.sh #合约:不动产业务缴税
完成后,结果显示
Get instantiated chaincodes on channel mychannel:
Name: estatebook, Version: 1.0, Path: github.com/chaincode/estatebook, Escc: escc, Vscc: vscc
Name: estatetax, Version: 1.0, Path: github.com/chaincode/estatetax, Escc: escc, Vscc: vscc
Name: netcon, Version: 1.0, Path: github.com/chaincode/netcon, Escc: escc, Vscc: vscc
此时链环境和链合约已经部署好了。下面开始部署项目的服务端和Web前台
代码位于appcode/fccserver/src 可自行编译,或直接使用已编译完成的可执行文件
chmod +x appcode/fccserver/src/fccserver
启动后台容器
./4.startAppcli.sh
docker logs -f appcli
如果启动正常,会显示
[fcc-server] 2019/12/12 03:03:55 system db initiated successfully.
[fcc-server] 2019/12/12 03:03:56 Chaincode client initialed successfully.
[fcc-server] 2019/12/12 03:03:56 Server started on :1206
前端采用VUE,也可使用其它前端框架或HTML。使用GNINX或其它WEB服务器部署编译后的前端代码。注:当前未使用登录和权限设置
前台部署依赖yarn
,《ubuntu 安装最新版本 yarn》
cd ./appcode/fcc-client // 进到Web前端代码目录
yarn install // 安装依赖
yarn serve // 运行前端
如果出现
运行成功后,就会显示访问地址
App running at:
- Local: http://localhost:8080/
- Network: http://192.168.31.134:8080/
浏览器打开地址,就能看到实例演示了
surou@surou:~/go/src/github.com/chaincode/netcon$ docker ps
+ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f3b34643ff39 dev-peer0.org2.example.com-estatebook-1.0-08d85d200f6268a9c9656f01eac3d5325c44c1d2a93a1115168f63888a27206b "chaincode -peer.add…" 44 minutes ago Up 43 minutes dev-peer0.org2.example.com-estatebook-1.0
9828c2b46b4e dev-peer0.org2.example.com-estatetax-1.0-975867dfc12f233b11d78db94c347aa6b7e94f1d389af7cc892cb8730652c110 "chaincode -peer.add…" 45 minutes ago Up 45 minutes dev-peer0.org2.example.com-estatetax-1.0
9d62c54bfd73 dev-peer0.org2.example.com-netcon-1.0-8285fea29f8449473340c346dc0b6716a084576593325a33707353426d7298dc "chaincode -peer.add…" 46 minutes ago Up 46 minutes dev-peer0.org2.example.com-netcon-1.0
cb870db589c4 hyperledger/fabric-tools:1.4.3 "./fccserver" About an hour ago Up About an hour 0.0.0.0:1206->1206/tcp appcli
33ad280f1f17 dev-peer0.org1.example.com-estatetax-1.0-3284f6d77599d92fad2da964008b3f4bb78573eeb938f40e2110de2089455dc3 "chaincode -peer.add…" About an hour ago Up About an hour dev-peer0.org1.example.com-estatetax-1.0
fa575e9548e3 dev-peer0.org1.example.com-estatebook-1.0-1804a11c573ccbef46e7cda2314c1d76edc2fb52b0f7f9d10ed2024c03343aff "chaincode -peer.add…" About an hour ago Up About an hour dev-peer0.org1.example.com-estatebook-1.0
75c50829fbb8 dev-peer0.org1.example.com-netcon-1.0-4faf315b9f1da5832e386fbae0d05157d269cff3802d770b0e8f135a69027796 "chaincode -peer.add…" About an hour ago Up About an hour dev-peer0.org1.example.com-netcon-1.0
15d29c21ed9a hyperledger/fabric-tools:1.4.3 "/bin/bash" 2 hours ago Up 2 hours Org3cli
d0ce2cc32019 hyperledger/fabric-peer:1.4.3 "peer node start" 2 hours ago Up 2 hours 0.0.0.0:12051->12051/tcp peer1.org3.example.com
9bcf5082db71 hyperledger/fabric-peer:1.4.3 "peer node start" 2 hours ago Up 2 hours 0.0.0.0:11051->11051/tcp peer0.org3.example.com
6f76cca2d809 hyperledger/fabric-tools:latest "/bin/bash" 2 hours ago Up 2 hours cli
04d61faad751 hyperledger/fabric-peer:latest "peer node start" 2 hours ago Up 2 hours 0.0.0.0:10051->10051/tcp peer1.org2.example.com
cdbffd49d7d2 hyperledger/fabric-peer:latest "peer node start" 2 hours ago Up 2 hours 0.0.0.0:8051->8051/tcp peer1.org1.example.com
d59fe735b96d hyperledger/fabric-peer:latest "peer node start" 2 hours ago Up 2 hours 0.0.0.0:9051->9051/tcp peer0.org2.example.com
4caeb0c062e0 hyperledger/fabric-peer:latest "peer node start" 2 hours ago Up 2 hours 0.0.0.0:7051->7051/tcp peer0.org1.example.com
431ad6029954 hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" 2 hours ago Up 2 hours 7054/tcp, 0.0.0.0:8054->8054/tcp ca_peerOrg2
4d69e9f76b1b hyperledger/fabric-couchdb "tini -- /docker-ent…" 2 hours ago Up 2 hours 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb0
1bcd9f89625f hyperledger/fabric-couchdb "tini -- /docker-ent…" 2 hours ago Up 2 hours 4369/tcp, 9100/tcp, 0.0.0.0:6984->5984/tcp couchdb1
cb46fd7307cf hyperledger/fabric-couchdb "tini -- /docker-ent…" 2 hours ago Up 2 hours 4369/tcp, 9100/tcp, 0.0.0.0:8984->5984/tcp couchdb3
ac996671c144 hyperledger/fabric-orderer:latest "orderer" 2 hours ago Up 2 hours 0.0.0.0:7050->7050/tcp orderer.example.com
c13cc3241b96 hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" 2 hours ago Up 2 hours 0.0.0.0:7054->7054/tcp ca_peerOrg1
01ce681daa6c hyperledger/fabric-couchdb "tini -- /docker-ent…" 2 hours ago Up 2 hours 4369/tcp, 9100/tcp, 0.0.0.0:7984->5984/tcp couchdb2
yarn config set ignore-engines true
v1.4 版本执行 ./byfn.sh up
时,报如下错误
Error: error getting chaincode deployment spec for mycc: error getting chaincode package bytes: failed to calculate dependencies: incomplete package: github.com/hyperledger/fabric/core/chaincode/shim
!!!!!!!!!!!!!!! Chaincode installation on peer0.org1 has failed !!!!!!!!!!!!!!!!
========= ERROR !!! FAILED to execute End-2-End Scenario ===========
跟脚本代码是从(github)以下逻辑报出的
installChaincode() {
PEER=$1
ORG=$2
setGlobals $PEER $ORG
VERSION=${3:-1.0}
set -x
peer chaincode install -n mycc -v ${VERSION} -l ${LANGUAGE} -p ${CC_SRC_PATH} >&log.txt // 此处
res=$?
set +x
cat log.txt
verifyResult $res "Chaincode installation on peer${PEER}.org${ORG} has failed"
echo "===================== Chaincode is installed on peer${PEER}.org${ORG} ===================== "
echo
}
跟下逻辑,意思是说,以下依赖未找到(github)
import (
"fmt"
"strconv"
"github.com/hyperledger/fabric/core/chaincode/shim" // 未找到
pb "github.com/hyperledger/fabric/protos/peer"
)
经过对比仓库分支代码,发现release-1.4
是有的,最新的master
分支已经删掉了。
直接参考2.0版本修改下吧
修改chaincode_example02.go
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"os"
"github.com/hyperledger/fabric-chaincode-go/shim"
pb "github.com/hyperledger/fabric-protos-go/peer"
)
并在同级目录新建go.mod
module github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/chaincode_example02/go
go 1.14
require (
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200128192331-2d899240a7ed
github.com/hyperledger/fabric-protos-go v0.0.0-20200124220212-e9cfc186ba7b
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/genproto v0.0.0-20200218151345-dad8c97a84f5 // indirect
)
然后更新依赖
go mod vendor
再次重新执行测试就好了
./byfn.sh down
./byfn.sh up
或者
go mod init chaincode
go get github.com/hyperledger/fabric/common/util@v1.4
go get github.com/hyperledger/fabric/core/chaincode/shim@v1.4
go get github.com/hyperledger/fabric/protos/peer@v1.4
http://blog.hubwiz.com/2020/03/12/fabric-2-external-chaincode/
https://github.com/SAPDocuments/Tutorials/issues/4415?tdsourcetag=s_pctim_aiomsg