基于Buchain ethchain跨链系统部署

 

基于Buchain ethchain跨链系统部署

原文地址https://www.b2bchain.cn/3662.html

 


BU链基本操作:

 


更换配置文件需,清空数据库 
./bin/bumo --dropdb
创建账户
./bin/bumo --create-account
结束BU进程
​
ps -ef |grep bu
​
kill -9 xxxxid
启动BU
./bin/bumo 
发送交易注意nonce值
​
{
/*发创建账户交易的JSON格式*/
/*js中可以这样写,转成JSON块就好*/
    items:[{
        private_keys:[],//填私钥,签名用
        transaction_json:{
            fee_limit: ,         //相当于gaslimit,必须写
            gas_price: ,         //单位gas价格,必须写
            nounce: ,           //source_addr的交易序号,必须写
            source_address: ""  //发送账号
            
            operations:[{       //这个是必填的,这个是巨坑
                type: ,        //发合约和发交易这个都是1
                create_account{ //创建普通账号
                    dest_address: ,  //目的地址
                    init_balance:      //初始的钱
                    priv:{            //权限
                        master_weight: 1,
                        thresholds: {tx_threshold:1} 
                    }  //普通账号这俩都是1,合约的话是一个0一个1
                } 
            }]      
        }
    }]
}
 

 

 

 

GETh常用命令

查询地址余额
eth.getBalance("0x6d3BcC912c41C282e3FBF11b64f28FE026EeC9cf")
挖矿
miner.start(1);admin.sleepBlocks(20);miner.stop();
结束全部geth
killall -HUP geth

 

从metamask导入到互联链
​
获取metamask私钥后
在geth客户端
personal.importRawKey("AF5E73277F1E5C4564E5BFB57C2DA30204F597A292C62EDA72FE88E830CCFE41","123456")
geth下转账操作
​
var acc1=eth.accounts[0]
​
personal.unlockAccount(acc1,"123456")
​
eth.sendTransaction({from: acc1 , to: "0x33A43Ff4A8e2B57bE24da7370c42bE6E9afb3297", value: web3.toWei(1000,"ether")})
Error: insufficient funds for gas * price value undefined
 
 1:remix产生 web3deploy信息与所选网络有关,需配置metamask链接网络信息包含网络ID
 2. 账号需有余额
解锁账户
personal.unlockAccount("0x6d3BcC912c41C282e3FBF11b64f28FE026EeC9cf","123456")

 

 

 

 


部署合约步骤

geth下解锁账户
personal.unlockAccount("0x6d3bcc912c41c282e3fbf11b64f28fe026eec9cf","123456")
remix在线编译生成
compilation detail 中找到 WEB3DEPLOY
复制到Geth命令行
挖矿
miner.start(1);admin.sleepBlocks(20);miner.stop();
生成合约lockcontract地址
Contract mined! address: 0x720abf08f31d3361b275ffef9fef600973056e76 

 

 

 


新建geth客户端节点

{
  "config": {
        "chainId": 39,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0,
"eip150Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0
​
    },
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x00000002",
  "extraData"  : "0xC5A3B1C6706C75732D32303139C4EA3132D4C23139C8D5A3ACB9A7CFB2C4E3A3ACBFB4B5BDD5E2B8F6B4B4CAC0C7F8BFE9B5C4B1B8D7A2",
  "gasLimit"   : "0xffffffff",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00",
  "alloc"      : {}
}
​
初始化 
geth --datadir chain39  init genesis.json
启动
 geth --datadir "./chain39" --networkid "39" --port "30039" --rpc --rpcaddr "0.0.0.0" --rpcport "8039"  console 2>>eth_chain39.log 
创建账号
> personal.newAccount("123456")
lockcontract合约地址
0x720abf08f31d3361b275ffef9fef600973056e76
部署合约出现错误
The contract code couldn't be stored, please check your gas amount. undefine
原因:gaslimit 限制俩部分 均需修改
1.创世区块部分 Genesis.json
2.生成WEB3DEPLOY gas字段
lockcontract合约
改用0.5.10+
由于编译版本问题
browser/LockContract.sol:248:9: TypeError: Type contract LockContract is not implicitly convertible to expected type address.
address myAddress = this;
^----------------------^
​
248行错误 改为 address myAddress = address(this);

 

 

合约调用
​
myAccount=eth.accounts[0];
contractAddres="0x8187f05e640a42d33778e6edcc5c2ee9b9d3154e";
 
abi=[ { "inputs": [], "payable": true, "stateMutability": "payable", "type": "constructor" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "string", "name": "str", "type": "string" } ], "name": "StrLog", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "bytes32", "name": "trans_Hash", "type": "bytes32" } ], "name": "ePreLock", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "from", "type": "address" }, { "indexed": false, "internalType": "address", "name": "to", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "eTransfer", "type": "event" }, { "payable": true, "stateMutability": "payable", "type": "fallback" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "gwAddr", "type": "address" }, { "internalType": "uint256", "name": "authState", "type": "uint256" } ], "name": "authGW", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [], "name": "doAward", "outputs": [], "payable": true, "stateMutability": "payable", "type": "function" }, { "constant": true, "inputs": [], "name": "getReigningGW", "outputs": [ { "internalType": "string", "name": "", "type": "string" }, { "internalType": "string", "name": "", "type": "string" }, { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "string", "name": "fromChainID", "type": "string" }, { "internalType": "string", "name": "from", "type": "string" }, { "internalType": "string", "name": "toChainID", "type": "string" }, { "internalType": "string", "name": "to", "type": "string" }, { "internalType": "string", "name": "nonce", "type": "string" } ], "name": "getResult", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "bytes32", "name": "txHash", "type": "bytes32" } ], "name": "getResultByHash", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address[]", "name": "newOrganizations", "type": "address[]" } ], "name": "initOrganizations", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "string", "name": "fromChainID", "type": "string" }, { "internalType": "string", "name": "from", "type": "string" }, { "internalType": "string", "name": "toChainID", "type": "string" }, { "internalType": "string", "name": "to", "type": "string" }, { "internalType": "string", "name": "valueFrom", "type": "string" }, { "internalType": "string", "name": "valueTo", "type": "string" }, { "internalType": "string", "name": "nonce", "type": "string" }, { "internalType": "uint256", "name": "blockNum", "type": "uint256" } ], "name": "lock", "outputs": [ { "internalType": "bytes32", "name": "", "type": "bytes32" } ], "payable": true, "stateMutability": "payable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "string", "name": "fromChainID", "type": "string" }, { "internalType": "string", "name": "from", "type": "string" }, { "internalType": "string", "name": "toChainID", "type": "string" }, { "internalType": "string", "name": "to", "type": "string" }, { "internalType": "string", "name": "valueFrom", "type": "string" }, { "internalType": "string", "name": "valueTo", "type": "string" }, { "internalType": "string", "name": "nonce", "type": "string" } ], "name": "preLock", "outputs": [ { "internalType": "bytes32", "name": "", "type": "bytes32" } ], "payable": true, "stateMutability": "payable", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "address", "name": "gwAccount", "type": "address" } ], "name": "queryGWInfo", "outputs": [ { "internalType": "string", "name": "sgx_account", "type": "string" }, { "internalType": "string", "name": "inner_account", "type": "string" }, { "internalType": "address", "name": "auth_organization", "type": "address" }, { "internalType": "uint256", "name": "state", "type": "uint256" }, { "internalType": "uint256", "name": "block_point", "type": "uint256" }, { "internalType": "uint256", "name": "pledge", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [], "name": "quitGW", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [], "name": "refundGW", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "sgx_account", "type": "address" }, { "internalType": "address", "name": "inner_account", "type": "address" } ], "name": "register", "outputs": [], "payable": true, "stateMutability": "payable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "string", "name": "fromChainID", "type": "string" }, { "internalType": "string", "name": "from", "type": "string" }, { "internalType": "string", "name": "toChainID", "type": "string" }, { "internalType": "string", "name": "to", "type": "string" }, { "internalType": "string", "name": "valueFrom", "type": "string" }, { "internalType": "string", "name": "valueTo", "type": "string" }, { "internalType": "string", "name": "nonce", "type": "string" }, { "internalType": "uint256", "name": "blockNum", "type": "uint256" } ], "name": "unLock", "outputs": [ { "internalType": "bytes32", "name": "", "type": "bytes32" } ], "payable": true, "stateMutability": "payable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "string", "name": "fromChainID", "type": "string" }, { "internalType": "string", "name": "from", "type": "string" }, { "internalType": "string", "name": "toChainID", "type": "string" }, { "internalType": "string", "name": "to", "type": "string" }, { "internalType": "string", "name": "valueFrom", "type": "string" }, { "internalType": "string", "name": "valueTo", "type": "string" }, { "internalType": "string", "name": "nonce", "type": "string" } ], "name": "withdrawal", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" } ]
 
//abi就上面最早复制的一段代码
 
lockContract=eth.contract(abi).at(contractAddres);
 
//然后myContract.xxx();就能调用合约里面的函数了,例如我的getBalance()
​
​

 

web3js前端调用
geth开启
geth --datadir "./chainA1" --networkid "19" --port "30019" --rpc --rpccorsdomain="*" --rpcapi "web3,eth,personal,net"  --rpcaddr "0.0.0.0" --rpcport "8019" console 2>>eth_chainA1.log

 

 

geth --datadir "./chain39" --networkid "39" --port "30039" --rpc --rpcaddr "0.0.0.0" --rpcport "8039" -allow-insecure-unlock  console 2>>eth_chain39.log 

需要加最后面的解锁账户,

BU链部署参考

https://github.com/bumoproject/bumo/blob/develop/docs/manual_CN.md

ETH链部署参考

https://my.oschina.net/u/2349981/blog/865256

查看私钥

https://blog.csdn.net/northeastsqure/article/details/79476831

remix本地

https://github.com/ethereum/remix-ide/releases

remixd 
​
安装
npm install -g remixd
使用
remixd -s <absolute-path> --remix-ide https://remix.ethereum.org
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Hello World程序员

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

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

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

打赏作者

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

抵扣说明:

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

余额充值