TheGraph 通过监听链上合约租赁事件,记录链上租赁订单数据,可使用 GraphQL 语法查询

各链TheGraph服务地址

前置内容

TheGraph Entity

leases (租赁市场订单数据)

# lease schema 
type Lease @entity {
  id: ID!                 # 订单 ID <nftaddress-tokenId>
  nftAddress: Bytes!      # NFT 合约地址
  tokenId: BigInt!        # NFT 编号 ID
  lender: Bytes!          # 出借者钱包地址
  erc20Address: Bytes!    # 租借者所支付的 ERC20 Token 合约地址
  whitelist: Bytes!       # 白名单地址(如果设置了白名单,将只允许白名单地址可以租借当前 NFT)
  deposit: BigInt!        # 押金
  rentPerDay: BigInt!     # 租赁 NFT 每天价格单价
  daysPerPeriod: BigInt!  # 租借者扣款周期(每隔 x 天支付一次租金)
  minRentalDays: BigInt!  # 最小可租金天数
  maxRentalDays: BigInt!  # 最大可租金天数
  renter: Bytes!          # 租借者钱包地址
  start: BigInt!          # 开始租借时间戳
  paidExpires: BigInt!    # 已支付租金的到期天数
  expires: BigInt!        # 当前租约的过期时间
  chain: String!          # 当前所处链
}
// result example
{
  "data": {
    "leases": [
			...
      {
        "id": "0x7e2997174d717b15fe029954ad1f380c5eb23169-1",
        "deposit": "330000000000000000",
        "start": "1663151357",
        "expires": "1663410557",
        "chain": "rinkeby",
        "nftAddress": "0x7e2997174d717b15fe029954ad1f380c5eb23169",
        "daysPerPeriod": "3",
        "erc20Address": "0x197fadc42067f43a32dad11c53962ede0c83e0ab",
        "lender": "0x576687d59d191a9b20110fb3e126dbf27d8e42e0",
        "maxRentalDays": "365",
        "minRentalDays": "1",
        "paidExpires": "1663410557",
        "rentPerDay": "330000000000000000",
        "renter": "0x0bd75f6e1b4acd5f6d90d8b7aa0600ac352f4e15",
        "whitelist": "0x0000000000000000000000000000000000000000",
        "tokenId": "1"
      },
      ...
		]
	}
}

TheGraph 查询示例如下,更多查询语法详见文档

query MyQuery {
  leases {
    id
    chain
    daysPerPeriod
    deposit
    erc20Address
    expires
    lender
    maxRentalDays
    minRentalDays
    nftAddress
    paidExpires
    rentPerDay
    renter
    start
    tokenId
    whitelist
  }
}
query MyQuery {
  leases(where:{ 
			lender: "0x576687d59d191a9b20110fb3e126dbf27d8e42e0"
	}) {
    id
    chain
    daysPerPeriod
    deposit
    erc20Address
    expires
    lender
    maxRentalDays
    minRentalDays
    nftAddress
    paidExpires
    rentPerDay
    renter
    start
    tokenId
    whitelist
  }
}
query MyQuery {
  lease(
			id: "0x7e2997174d717b15fe029954ad1f380c5eb23169-2"
	) {
    id
    daysPerPeriod
    deposit
    erc20Address
    expires
    lender
    maxRentalDays
    minRentalDays
    nftAddress
    paidExpires
    rentPerDay
    renter
    start
    tokenId
    whitelist
  }
}