web3.js支援SimpleChain跨鏈呼叫
阿新 • • 發佈:2020-07-06
SimpleChain的跨鏈協議已經對外開放很久了,很多應用也已經慢慢支援Simplechain的跨鏈。最近社群開發者web3.js中集成了Simplechain的跨連結口,開發者只需用npm
安裝包檔案。參考原生 RPC介面的引數,就可以快速上手接入Simplechain跨鏈。下面是詳細流程;
檢視RPC介面
首先我們需要熟悉Simplechain的跨鏈 介面,熟悉了介面以後我們就可以直接上手操作。
安裝包檔案
首先你需要安裝node環境,然後使用npm安裝跨鏈包。命令如下:
npm install @sipc/web3
安裝完以後就可以在你的工程專案面整合跨鏈。主要的方法有:getCtxQuery
getCtxOwner
,getCtxOwnerByPage
,getCtxContent
,getCtxContentByPage
,ctxGet
,ctxGetByNumber
, ctxQueryDestValue
, getCtxTakerByPage
, getCtxStats
, getPoolStats
。
使用示例
const rpcUrl = "http://192.168.4.104:8546"
const Web3 = require('@sipc/web3')
const web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl));
(async function () {
const blockNumber = await web3.eth.getBlockNumber()
const chainId = await web3.cross.net.getId()
const owner = await web3.cross.getCtxOwnerByPage("0x6407d2a4cd26fdd884dc2ed4a4f8882e413d84f6", 2, 1)
const poolStats = await web3.cross.getPoolStats()
const stats = await web3.cross.getCtxStats()
for(const item of owner.data['909']){
console.log(item.txHash)
}
console.log(blockNumber, chainId, owner, poolStats, stats )
})()
以上就是Simplechain的跨鏈SDK使用方法,如果你在使用過程中遇到任何問題可以新增我們的技術社群負責人微信:youths_1994。加入我們的社群一起討論