Queries
Make a view call across chains using IQS.
This tutorial demonstrates how to make a simple interchain view call via the Queries API from pre-deployed TestQuerySender
contracts to any arbitrary target on which Hyperlane is deployed.
Inputs
$DESTINATION_DOMAIN
: The domain ID of the destination chain. You can use43113
to send to Fuji, or choose from any of the known Domain identifiers$TARGET
: The address of the contract on the destination chain you want to query. You could just query for theowner()
of theInterchainAccountRouter
contract which is found at0xc61Bbf8eAb0b748Ecb532A7ffC49Ab7ca6D3a39D
on every testnet chain$TARGET_DATA
: The ABI encoded call, if you want to make anowner()
call that would be0x8da5cb5b
$GAS_AMOUNT
: The amount of gas on the destination chain to pay for. For the simpleowner()
example, we can set this to a generous200000
gas. See Interchain gas payments to learn more.
How TestQuerySender works
TestQuerySender
calls theInterchainQueryRouter
and designates a callback function for the result of the query itself. It will Automatically pay for interchain gas.
Make a query
Getting the Interchain Gas Payment Quote
Under the
Contract
tab, selectRead Contract
.Expand the
quoteGasPayment
function.For the destination domain, enter
$DESTINATION_DOMAIN
.For gas amount, enter
$GAS_AMOUNT
, which is200000
.Click
Query
and make note of the amount returned as$GAS_PAYMENT_QUOTE
. For example, at the time of writing, the quote is1
wei.
Making the Query
Navigate to the
TestQuerySender
0x96D7D6Eba6C635e3EaC12b593Ef8B2eE1F6E6683
contract page on Etherscan (or whatever chain you want to send from - on testnets the TestQuerySender is always found at0x96D7D6Eba6C635e3EaC12b593Ef8B2eE1F6E6683
, and on mainnets it's0x8566F965f613cB47A5Bd59879d07186122590895
)Under the
Contract
tab, find theWrite Contract
button.Click on the
Connect to Web3
button to connect your Wallet (i.e. Metamask). Make sure that you are on the correct network.Expand the
queryAddress
box.For the payable amount, Etherscan expects an amount quoted in ether, while our
$GAS_PAYMENT_QUOTE
is in wei. To convert from wei to ether, input the amount$GAS_PAYMENT_QUOTE
, which is in wei, into https://eth-converter.com/ and copy the ether amount. Use this ether amount as the payable amount.For destination domain, enter
$DESTINATION_DOMAIN
.For the target, enter
$TARGET
, i.e. the address of the contract you like to query on the destination.For target data, enter
$TARGET_DATA
, i.e. the ABI encoded call of the query itself.For gas amount, enter
$GAS_AMOUNT
.Submit the transaction via your wallet/Metamask
If you view the transaction on a block explorer, you should be able to see the Dispatch
event. You can see an example message sending transaction here.
Confirm query
You can use the Hyperlane Explorer to show the delivery of the message for the query to the destination. When it gets delivered (example), the delivery transaction will actually be also the origin tx hash for the delivery of the result back to the origin. Once again, you can use the Message Explorer to check on the delivery of that message (example). When all is done, you can see how the query result was persisted on the TestQuerySender
contract by going to the Contract => Read Contract
page and expanding the lastAddressResult
section.
Last updated