ERC-20 allows the implementation of a standard API to ensure the interoperability between tokens. It offers basic functionalities to transfer tokens, obtain account balances, get the total supply of tokens, and allow token approvals. You can read more about their API and methods here: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
Let’s see how HAL can helps us interact with any token that follows the ERC-20 standard, with some real-world examples:
The method transferFrom
:
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf, and it must fire the Transfer event Transfer(msg.sender, _to, _value)
;
we can therefore create an Event Trigger
that looks for events emitted and sends us an email every time a smart contract transfers any amount of tokens from our account:
EventsTriggers -> Create new
In Smart contract address, insert the address of the token you want to track. E.g. If you want to track the MakerDAO’s stablecoin, insert 0x6b175474e89094c44da98b954eedeac495271d0f
From the "contract event to watch" dropdown menu, select Transfer
If you want to track sent tokens, insert your address in from
If you want to track the token you receive, insert your address in to
. You can also specify a range in the value
field, for example to filter transactions that move more than X coins.
The standard also implements a method balanceOf
for returning the account balance of another account:
function balanceOf(address _owner) public view returns (uint256 balance)
Say that we want to monitor whether the balance for a specific address drops below a certain threshold. We can call it directly with a Watch a Contract Trigger:
Contracts Triggers > Create new
If you want to track the MakerDAO’s stablecoin, insert 0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2
From the Contract function to watch menu, select balanceOf
In the field src [address]
, insert the address you want to track.
In the field returns
, enter the threshold value that you want the trigger to be fired if the balance drops below.
Minting and Burning are implemented using a Transfer
with a specific from field, which emits a Transfer event with the address set to 0x (see an example here). You can create a Trigger that fires every time tokens are mint this way:
Events Trigger > Create new
If you want to track the MakerDAO’s stablecoin, insert 0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2
From the Contract function to watch menu, select Transfer
In the From
field, insert 0x0000000000000000000000000000000000000000000000000000000000000000
The Approval
event is fired on any successful call to approve(address _spender, uint256 _value)
. We can create a Trigger that is fired every time some funds are withdrawn from your account:
EventsTriggers -> Create new
In Smart contract address, insert the address of the token you want to track. E.g. If you want to track the MakerDAO’s stablecoin, insert 0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2
From the "contract event to watch" dropdown menu, select Approval
Under the owner
field, insert your own address
You can leave spender
empty, or track a specific spender
You can leave value
empty, or track any transfer that moves a particular amount of tokens.