• web3.js支持SimpleChain跨链调用


    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。加入我们的社群一起讨论

  • 相关阅读:
    96. Unique Binary Search Trees
    515. Find Largest Value in Each Tree Row
    网络中数据传输的过程
    ARP/RARP协议
    JAVA静态代码块的作用及执行顺序
    MySQL中大于等于小于等于的写法
    Mybatis常见面试题总结及答案
    安全框架Shiro和Spring Security比较
    Excel VBA 连接各种数据库(一) VBA连接MySQL数据库
    Servlet、Servlet容器等内容讲解
  • 原文地址:https://www.cnblogs.com/sipc/p/13255815.html
Copyright © 2020-2023  润新知