Transferring ERC-20 tokens with Delphi

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

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

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

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 fishing 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 test network (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.5 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

  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

What we will do is create a simple Hello World program that will transfer 0.001 TST from 0x29565d2B25a0D40E1245fa3eC8b7D9d007941aBe to 0xaDDcedc01C1070bCE0aF7eb853845e7811EB649C.

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.

--

--

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Stefan

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