Transferring ERC-20 tokens with Delphi

Stefan
5 min readMar 30, 2019

--

In a previous article, we transferred ether with Delphi. While ether is the number one cryptocurrency on the Ethereum blockchain, the network actually hosts thousands of other cryptocurrencies. Most of these other cryptocurrencies are known as ERC-20 tokens.

ERC-20

ERC-20 is a smart contract interface on the Ethereum blockchain for implementing tokens. ERC stands for Ethereum Request for Comment, and 20 is the number that was assigned to this request. Most of the tokens issued on the Ethereum blockchain are ERC-20 compliant. Because all ERC-20 tokens must adhere to the ERC-20 standard, it is super easy for an exchange to list them because from the technical perspective they all are basically identical. Among the most successful ERC-20 tokens are BNB and DAI and USDT.

Because we do not want to buy any real-world ERC-20 tokens at this time (nor spend any real-world gas on transactions), we will be using the Goerli testnet (not the Ethereum mainnet).

Goerli

The Goerli testnet (launched early 2019) is essentially a testing environment that you can use before you bring your code onto the mainnet. When developers are building dapps, or experimenting on the network, they use the Goerli testnet to avoid losing money paying real-world ether for transaction fees and smart contract deployments.

Before we can transfer an ERC-20 token on the Goerli testnet, we need some test ether in a wallet. Test ether carries no real-world value, but we need some to pay for transaction fees. The easiest way to get some test ether is to request it from a so-called faucet. And the easiest way to load up your account with faucet ether is via MetaMask.

MetaMask

MetaMask is a feature-rich Ethereum wallet for Chrome and Firefox and Brave and Opera. MetaMask supports the Goerli testnet and makes it super easy to load up your account with test ether.

Please install MetaMask via a reputable source. Unfortunately, there are many bad actors out there trying to trick you into installing an imposer MetaMask extension into your web browser. In essence, they are then phishing for your private key.

Be extremely careful entering your private key into a web browser environment. Whenever the web browser (or any app for that matter) asks you for your private key, a big red alarm must go off in your head and you should double-verify what you are doing.

For the purpose of this article, we will create a new account with MetaMask. Please follow these steps, then come back to this article.

Assuming you have successfully created a new account with MetaMask, now please follow these additional steps:

  1. Click on the MetaMask icon
  2. Unlock MetaMask with your MetaMask password
  3. You should see the MetaMask main menu. In the top of this window, click on Ethereum Mainnet
  4. A popup window appears. Click on Goerli (if Goerli isn’t visible, you might need to click on show/hide test networks first)
  5. follow this link https://goerlifaucet.com
  6. Paste your (MetaMask test account) address and click on Send Me ETH

Congratulations! You have successfully acquired 0.02 test ether in your MetaMask wallet on the Goerli testnet.

Before we can transfer an ERC-20 token, we need some of that in our wallet, too. In the real world, we would go to an exchange and then buy an ERC-20 token on the Ethereum mainnet. Because we are currently on Goerli, what we need is an ERC-20 token on the Goerli testnet.

TST

TST is a test token on the Goerli network. Because TST is an ERC-20 token, it adheres to the ERC-20 smart contract interface. Etherscan has a feature called Write Contract and it allows to directly interact with the TST smart contract through the use of MetaMask.

  1. Navigate to the TST smart contract
  2. Click on Write Contract
  3. Click on Connect to Web3
  4. Scroll down to where it reads showMeTheMoney
  5. Paste your (MetaMask test account) address in _to
  6. Enter “1000000000000000000” (no quotes) in _value (uint256)
  7. Click on Write
  8. You should be greeted with this (MetaMask) dialog:

Congratulations! You have successfully acquired one whole TST token in your MetaMask wallet on the Goerli testnet.

Phew. Those were a lot of steps. Thank you for hanging in there. Now that we have a wallet on a testnet loaded up with both test ether and a test ERC-20 token, we can turn our attention to Delphi.

Delphereum

Clone Delphereum and the dependencies. Launch Delphi. Start a new project. Please make sure the dependencies are in your search path.

What we will do is create a simple Hello World program that will transfer 0.001 TST from public address 0x29565d2B25a0D40E1245fa3eC8b7D9d007941aBe to public address 0xaDDcedc01C1070bCE0aF7eb853845e7811EB649C (please note these addresses are just examples and you should replace them with your own).

Drop a Button component on your newly created main form. Then double-click on the Button component, and add the following code to the OnClick event handler:

Please note that you will need to change the Infura URL in the above example. If you don’t know what Infura is or does, please refer to this article.

Run your newly created Delphi project (F9) and click the Button component. Your program should respond with a transaction hash:

You can now look up this transaction hash on etherscan. If there weren’t any errors, then you should see a successful transaction:

Congratulations! You have successfully transferred an ERC-20 token with Delphi.

--

--

Stefan
Stefan

Written by Stefan

Delphi/Rust/Go developer. Ethereum consultant. Embarcadero MVP. Ex-Adobe, Macromedia. Helped build 1Password.

No responses yet