Once a contract is verified, contract methods are exposed and contract interaction is possible directly from OpenScan.AI.
In the following examples we use OpenScan.AI on XDC Network (xdcscan.io). Make sure your web3 wallet (like MetaMask) is also connected to XDC Network when reading / writing to a contract.
Read Contract
Read actions let you check various contract attributes. You will need to connect a web3 wallet to make a query, though a query does not require a transaction or any gas costs.
- Find the contract address you want to interact with and enter it into the search bar. In this example we search for an ERC-20 token on XDC Network.
- We select the first option in search and are taken to the token page. We can interact from here, but would prefer to see more information about the contract, so we click through to the contract page.
- Scrolling down past the contract details we see the code is verified by the checkmark ✅. If the code is not verified, it is not possible to read or write to a contract (unless a verified contract with the same bytecode is located in the OpenScan.AI database. In this case read/write will also be available).
- We know this is a proxy implementation by the fact that there are options to either read/write to the contract or to the proxy. Proxy means that the contract is upgradeable, and the admin can set a new implementation address for the proxy contract if upgrades are required.
We will choose to Read Proxy, since it contains all the relevant methods for the current contract implementation.
- We can see the various methods within the proxy contract. Some show current values and others are queryable. An easy example to query is the
balanceOfmethod. - This method expects an address and will output an integer. Simply paste in a
0xaddress and press Query to see the token balance held by that particular address. If your web3 wallet is not connected at this point, you will be prompted to connect.
The result shows the raw token balance. (Note: ERC-20 tokens allow for custom decimal point precision. Many tokens use 6 decimal precision, and many others use 18 (to denote wei), so be sure to check the token implementation for conversion info.)
Write Contract
Many write functions can only be performed by an approved owner. Connect the owner wallet when performing gated functions.
- We’ll use OpenScan.AI to transfer tokens from one address to another. You can perform this action directly through a wallet UI; we use the OpenScan.AI interface here for demonstration purposes. Type the contract address into the search bar, scroll down, and select Write Proxy.
- We scroll down to find the
transferFrommethod.
Boxes are filled with the following information:
-
_sender(address): The0xaddress sending the tokens. Note this account is the one to connect to OpenScan.AI to write to the contract. -
_recipient(address): The0xaddress receiving the tokens. -
_amount(uint256): Amount to transfer. If the token uses 6 decimals of precision, we enter 500000 to denote 0.50 tokens — for other tokens this can differ. -
We press the Write button, and MetaMask or another web3 wallet takes us through the transaction. If a wallet is not connected, there will be several prompts to connect an account to OpenScan.AI. Once connected, we confirm the transaction.
The connected wallet must contain enough native tokens (XDC on XDC Network) to pay gas for the transaction.
- We can check our wallet to confirm the transaction, and can view tx details in OpenScan.AI (or return to the Read Contract
balanceOfmethod to view new balances for the addresses).