web3.js支持SimpleChain跨链调用
时间: 2020-07-06来源:OSCHINA
前景提要
【围观】麒麟芯片遭打压成绝版,华为亿元投入又砸向了哪里?>>>
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 。
使用示例
npm库 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。加入我们的社群一起讨论

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行