Content 合约请求示例

我们使用Relation Protocol部署好的Relation Content合约,可以实现用户身份数据的存储与查询。Relation Content合约是对Contract Standard里Content的实现。

构建Contract对象

Content以及ContentWithSign的合约地址以及abi文件可以查询Relation Protocol资源列表获得,通过ethers构建Contract对象:

import { ethers, providers } from 'ethers'

const getContractInstance = () => {
  // 合约地址
  const contractAddress = '0xAC0f863b66173E69b1C57Fec5e31c01c7C6959B7'
  const provider = new providers.Web3Provider(window.ethereum)
  const signer = provider.getSigner()
  const contract = new ethers.Contract(contractAddress, contentAbi, signer)
  return contract
}

const getContentWithSignContractInstance = () => {
    // 合约地址
    const contractAddress = ''
    const provider = new providers.Web3Provider(window.ethereum)
    const signer = provider.getSigner()
    const contract = new ethers.Contract(contractAddress, contentWithSignAbi, signer)
    return contract
}

调用合约方法

用户自付Gas费

  1. 发布内容

用户可以将需要发布的内容上传至Arweave,内容格式为:

上传后得到的交易哈希,作为content记录至合约中

  1. 查询用户发布的内容列表

遍历出用户的token列表,即可得到其发布的内容列表

代付Gas费

用户对数据进行签名,构建上链参数。任意地址可携带此上链参数调用合约发起交易,Gas费由发起交易的地址支付。

  1. 发布内容(代支付Gas费)

用户可以将需要发布的内容上传至Arweave,内容格式为:

上传后得到的交易哈希,构建上链参数。由实际支付Gas费的地址携带此上链参数调用合约。

Last updated