Skip to main content
How to set up a contract query
Brigitta Pajer avatar
Written by Brigitta Pajer
Updated over a week ago


This feature allows you to call read functions from deployed smart contracts across multiple chains, and compare the returned value to a predefined value.

A read function is a type of function that retrieves data from the blockchain without altering its state. They are used to query information like token balances, user data, or contract states.


In this example, we will set up a contract query requirement that checks if a user’s USDT balance is more than 100 tokens. For this, we need to select Contract query from the Add requirement popup.

After that, we need to select the chain and enter the contract address. In this example, we will use the USDT contract on the Ethereum chain, which you can see here:

We can copy the contract address from the chain’s explorer.

If the contract source code is verified, Guild will be able to automatically detect read functions. The contract is verified if there is an approval mark on the contract tab. You can verify your contract if you upload the source code to the explorer.

From this list you need to select the query you want to use for your specific purpose. For this example, we will select the balanceOf method.

After selecting the method, Guild automatically detects the amount of inputs and outputs. Since there is only one input and one output in the balanceOf method, it makes our job easier. The first input is an address, which will be the user's address, so we enter USER_ADDRESS. The expected output is the amount we want to compare it to.

Here you just need to enter a predefined amount. After entering, select the needed comparison type, in this case, bigger than or equal.

NOTE: Tokens have a property called decimals, which indicates the number of decimal places a token uses. This is crucial for understanding the token's value. For example, if a token has a decimal value of 18, it means you need to add 18 zeros after a whole number to get its actual value. In other words, 1 token is represented as 1 * 10^18 units. The USDT token has 6 decimals, which means you need to enter 100 000 000 to represent 100 USDT. You don’t need to worry about this when using the token requirement.

Just click Add requirement to save it, and any user who has a balance of more than 100 USDT tokens should get access. (If you want to token gate we recommend you to use the token requirement, which takes care of decimals.)

Did this answer your question?