Connecting Delphi to the Ethereum main net

In a previous article, we connected Delphi to a local (in-memory) blockchain. In this article, we will connect Delphi to the Ethereum main net.

Ethereum is a distributed computing platform that consist of more than 8,000 active and listening nodes, where every node holds a copy of the blockchain. If you want to connect to the blockchain, you’ll will need to connect to a node.

Running your own node can be challenging. Luckily, there are services out there that simplify this procedure for you, such as QuikNode and Infura. In essence, these so-called remote nodes will keep the software up-to-date for you, protect your node against DDoS attacks, etc. They take the hassle away of setting up and running your own node.

In this example, we will use Infura. Go to the Infura web site and sign up for a free account. Infura will give you a project ID. If you want to connect to the Ethereum main net, then your endpoint for that will look like this:

https://mainnet.infura.io/v3/your-project-id

What we will do is create a simple Hello World project that connects to the Ethereum main net and then get the balance of an account. Nothing more, nothing less.

Launch Delphi, and then start a new project. Please make sure both the BigNumbers and Delphereum libraries are in your search path.

Drop an Edit and 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 the URL in the example above is for Ganache, not the Ethereum main net. Replace that URL with your Infura endpoint.

Now open etherscan.io in your web browser. Etherscan is a so-called blockchain explorer, where you can easily lookup, confirm and validate transactions that have taken place on the blockchain. Navigate to the following web page:

https://etherscan.io/accounts

This page will give you the top accounts by ether balance. Yes, there are some very rich people out there.

Click on a top 10 account. You are then taken to a detail page where you can copy the account address to the clipboard.

Run your newly created Delphi project (F9) and paste the address of the Ethereum account into the Edit component. Now click on the Button. You should be greeted with this dialog:

Congratulations! You have successfully connected a native application to the Ethereum main net. In the next article, we will connect Delphi to a smart contract.

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

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