import gql from 'graphql-tag' ; import { blockClient } from './client' ; export const GET_BLOCK = gql `
  query blocks($timestamp: BigInt!) {
    blocks(first: 1, orderBy: timestamp, orderDirection: asc, where: { timestamp_gt: $timestamp }) {
      id
      number
      timestamp
    }
  }
` ; param timestamp export async function getBlockFromTimestamp ( timestamp ) { const result = await blockClient . query ( { query : GET_BLOCK , variables : { timestamp : '' + timestamp } , fetchPolicy : 'cache-first' } ) ; return result ?. data ?. blocks ?. [ 0 ] ?. number ; }