Best Practices

Some of the best practices when using Say API

Get Query Fee

For each query, There requires enough AE tokens in your smart contracts to cover the Oracle fee. If there are not enough tokens then the query will not be asked and you might want to handle this gracefully. You can use method such as Say.getBaseFee() to get the current oracle fee in your smart contract and send only enough tokens through query.

Mapping Query Ids

It might be helpful to initiate a mapping that manages the query ids and their states. When the callback function of a query gets called, the require statement checks if the current query id needs to be processed. After one successful iteration the id gets deleted to prevent further callbacks for that particular id.

Create mapping of pending queries myIds: map(bytes32, bool). Set created query to true myIds[bytes32] = true . After getting answer from the query, find the key from the mapping then Map.delete(bytes32, myIds)