Connecting Delphi to a local (in-memory) blockchain

In this article, we will connect Delphi to a local (in-memory) blockchain using Delphereum, a web3 implementation for the Delphi programming language.

What is Delphi?

What is Ethereum?

Step #1. Clone GitHub repositories

Because Ethereum denotes balances in wei (aka the smallest subdivision of ether), we first need to clone Rudy Velthuis’ excellent BigNumbers library:

git clone https://github.com/svanas/DelphiBigNumbers

Next up are Ugochukwu Mmaduekwe’s excellent crypto libraries:

git clone https://github.com/Xor-el/SimpleBaseLib4Pascal
git clone https://github.com/Xor-el/HashLib4Pascal
git clone https://github.com/Xor-el/CryptoLib4Pascal

Last but not least is Delphereum, a web3 implementation for the Delphi programming language:

git clone https://github.com/svanas/delphereum

Step #2. Download Ganache

https://trufflesuite.com/ganache

Download and start Ganache. You should see the following screen. The important thing to take away here is RPC server address, circled in the below screen shot. You will need that address later.

Ganache will give you 10 accounts. Each account is given 100 ether. When you close and then restart Ganache, you then reset the blockchain and return to this default 10-accounts-with-100-ether setup.

Step #3. Start a new Delphi project

Launch Delphi, and then start a new project. Please make sure the dependencies (cloned above) 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:

Because calls to the Delphereum library are asynchronous, the web3.eth.getBalancefunction expects a so-called promise. Inside this anonymous method, we need to synchronise the execution state with the main thread, and that is what TThread.Synchronizedoes for us.

Step #4. Get the balance of an Ethereum account

Switch back to your Delphi application and paste the address of the account into the Edit component. Now click the Button component. You should be greeted with this dialog:

Congratulations! You have successfully connected a native application to a local (in-memory) Ethereum blockchain. In the next article, we will connect Delphi to the Ethereum main net.

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

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

Stefan

258 Followers

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