Interacting with ICON Bridge contracts (proxy contracts) on EVM chains. #681
FidelVe
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a quick explanation/tutorial for developers that want to interact with ICON Bridge contracts (proxy contracts) on EVM chains.
Proxy contracts on EVM chains stores the address of the logic contract and delegates all function calls to the logic contract (which holds the business logic) using the delegatecall function. After the call is forwarded to the logic contract, the returned data from the logic contract is retrieved and returned to the user.
As a practical example lets interact with the BTS contract on the BSC testnet using javascript (web3.js).
To interact with the BTS contract is necessary to call the proxy contract directly and the proxy contract will pass the call to the logic contract.
Using web3.js we can do this with the following method call:
As you can see in the previous code example we still need one variable, the
BTSLogicContractABI
in order to create the contract object that we are going to use to interact with the ICON Bridge using web3.js.On EVM chains the ABI data is not available on chain, there are 2 ways to obtain that data:
For this example you can fetch the ABI data directly from the bscscan tracker either using the
https
module onnodejs
or afetch
call with js in the browser. The following is an example of getting the ABI withcurl
from a shell:curl "https://api-testnet.bscscan.com/api?module=contract&action=getabi&address=0xE020d4aD483C7eC90a24d9db502e66564eF9c236&format=raw"
Is important to notice that we are getting the ABI of the
BTSLogicContract
and not the ABI of theBTSProxyContract
, as explained previously, the correct ABI with the methods to interact with the ICON Bridge (or any evm proxy contract pattern) are on the logic contract not on the proxy contract, but you have to make the query to the proxy contract because this is the one that will forward this call to the logic contract and handle the proper reply back.Once we have the proper ABI data we can continue creating the contract object and making the method calls that we wish to make to the BTS proxy contract.
The following is a working example using
nodejs
(is necessary to previously install theweb3
library)Beta Was this translation helpful? Give feedback.
All reactions