ABI Transaction

This section explains how to use MyEtherWallet and Metamask to perform an ABI transaction in the Eco Protocol. ABI transactions allow users to submit transactions to the Ethereum network for functions in the Eco Protocol where no Web Application exists.

Using MyEtherWallet

1) In this example, we will go through an example of how to stake ECOx in the staking contract using an ABI transaction. First, we will go to the MyEtherWallet website.

2) MyEtherWallet allows you to connect your wallet to submit transactions using a graphical interface that uses an "ABI", which stands for "Application Binary Interface". This tells your wallet which functions are available for a given smart contract, and how to structure the inputs. Click on the "Access my wallet" button.

3) Select the wallet you use. For this tutorial, we will use the popular Metamask wallet. This should display the below interface. If you don't see the "Interact with Contract" interface, it is accessible under the "Contract" sidebar.

4) The "Interact with Contract" function asks for a contract and for an ABI interface. To get the contract, we will query the "Root Policy Address", but first we will need a detour to get the ABI documents.

5) This will require a GitHub account and we will clone the main Eco Currency repo, and build the ABI files. Open a terminal, and paste the following instructions in the terminal.

git clone https://github.com/helix-foundation/currency.git
cd currency
npm install
npm build

6) This should succeed, and should show that Solidity files are built. The built solidity files contain the ABI you need to interact with the contract. The ABIs will be located in the currency folder you cloned under the path artifacts/contracts folder.

7) We will first call the root policy contract to determine where the ECOx and ECOxStaking contract is. To find the policy ABI, navigate to artifacts/contracts/policy/Policy.sol/Policy.json and open the file.

8) Copy everything from the file after "abi": and up to "bytecode": and delete the comma at the end. Paste this into the ABI section on MyEtherWallet.

9) Paste in the root policy address (0x8c02D4cc62F79AcEB652321a9f8988c0f6E71E68), and press interact with contract.

10) Navigate to the drop-down menu, and select the PolicyFor function. The input uses the ERC1820 register to look up where active functions are.

11) An easy way to calculate the hash to put in "_interfaceIdentifer input" is this online tool to hash the contract name you are looking for. Putting in "ECOx" yields e10ab6c94f1da69921a0ca1c1b96b4fc339699153931c9bfd565e91f44c19b0b which we put in the input field of the interface.

12) Call the function. The output is the address of the ECOx contract we are looking for. Record this contract address.

13) We are also going to get the address of the ECOxStaking contract. Using the same process, we get the hash of 3776fba25fb0e7d0848ec503ec48569754f9d46736d6ace08b6eed818399d8e1.

14) Recall the function with the new hash. Also, record this contract address.

15) We now need to approve the ECOx transfer to the staking contract and stake the ECOx.

16) We are going to interact with the ECOx contract first. Exit out of the interface for this contract, and load in the contract address and ABI for the ECOx contract. The ABI is located at artifacts/contracts/currency/ECOx.sol/ECOx.json.

17) Using this ABI, we are going to call the Approve function. This transaction gives the staking address permission to transfer your ECOx.

18) The spender address is the ECOxStaking contract address from step #14.

19) The amount is the amount of ECOx units you want to stake. ECOx has 18 decimals, meaning that 1 unit of ECOx is represented by 1000000000000000000.

20) Write the transaction, and approve it in Metamask. Once confirmed, we can move to the ECOxStaking contract.

21) Exit this interface, and load up the ECOxStaking contract. The ABI is located at artifacts/contracts/governance/community/ECOxStaking.sol/ECOxStaking.json.

22) We are going to call the Deposit function. This is the final step to stake your ECOx in the staking contract!

23) Call the Deposit function with the value you approved from step #19. Write the transaction and approve it in MetaMask.

24) Once the transaction confirms, you're done! If you would like to track the amount of Staked ECOx in your wallet, navigate to the staking transaction on Etherscan, and find the s-ECOx token in the transaction information. Use its contract address to add it to your MetaMask.

25) Note, s-ECOx is not transferable. To withdraw the ECOx, simply call the Withdraw function in using the ECOxStaking ABI, with the same value you deposited!

Hopefully, this guide was a helpful example of how ABIs can be used to directly interact with a contract!

Last updated