Reactjs 从react with ether.js查询稳定视图函数的最佳方法?

Reactjs 从react with ether.js查询稳定视图函数的最佳方法?,reactjs,ethereum,solidity,use-effect,ethers.js,Reactjs,Ethereum,Solidity,Use Effect,Ethers.js,js与我的智能合约交互。我的合同具有如下功能,例如: function getOfferById(uint256 _tokenId) public view returns (uint256) { require(_tokenId < MAX_B, "This tokenId does not exist"); uint256 offer = bOffers[_tokenId]; require(offer > 0, "The

js与我的智能合约交互。我的合同具有如下功能,例如:

  function getOfferById(uint256 _tokenId) public view returns (uint256) {
    require(_tokenId < MAX_B, "This tokenId does not exist");
    uint256 offer = bOffers[_tokenId];
    require(offer > 0, "There is no offer for this token");
    return offer;
}
但是通过这种方式,我总是从metamask中得到很多控制台错误,因为require语句经常命中

解决此问题的最佳方法是什么?

在哪个
require()
上失败?第一个还是第二个。。。如果是第一个,您是在同一个合同上查询多个
id
s,还是在多个合同上查询?合同是否执行了。。。如果是第二个属性,
bOffers
a
public
属性?
useEffect(() => {
    async function getOfferById() {
      if (myContracts) {
        const _getOfferById = myContracts.getOfferById;
        if (_getOfferById && id) {
          try {
            const _offer = await _getOfferById(id);
            setoffer(formatUnits(_offer, 'ether'));
          } catch (e) {
            setoffer(0);
          }
        }
      }
    }
    getOfferById();
  }, [myContracts, id, myEventOfferCreated, myEventOfferCanceled]);