Skip to content

Instantly share code, notes, and snippets.

View svanas's full-sized avatar

Stefan svanas

View GitHub Profile
@svanas
svanas / Unit1.pas
Last active December 18, 2023 12:10
Listen on Blocknative's mempool WebSocket API
uses
// Delphi
System.Classes,
System.JSON,
System.UITypes,
// FireMonkey
FMX.Controls,
FMX.Controls.Presentation,
FMX.Dialogs,
FMX.Forms,
@svanas
svanas / Unit1.pas
Last active October 2, 2023 10:59
QuikNode
var client: IWeb3 := TWeb3.Create('https://<your-node-name>.discover.quiknode.pro/<your-token>/');
web3.eth.blockNumber(client, procedure(num: BigInteger; err: IError)
begin
TThread.Synchronize(nil, procedure
begin
if Assigned(err) then
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0)
else
MessageDlg(num.ToString, TMsgDlgType.mtInformation, [TMsgDlgBtn.mbOK], 0);
end);
@svanas
svanas / Unit1.pas
Last active October 1, 2023 13:37
setNumber()
web3.eth.write(Client,
TPrivateKey('b5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7'), // from private key
'0x1a306890df22c0965b0b1515a8082f8301d3d18e', // to smart contract
'setNumber(uint256)', [143],
procedure(rcpt: ITxReceipt; err: IError) begin end);
@svanas
svanas / Unit1.pas
Last active October 1, 2023 13:34
incrementNumber()
web3.eth.write(Client,
TPrivateKey('b5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7'), // from private key
'0x1a306890df22c0965b0b1515a8082f8301d3d18e', // to smart contract
'incrementNumber()', [],
procedure(rcpt: ITxReceipt; err: IError) begin end);
@svanas
svanas / Unit1.pas
Last active October 1, 2023 13:32
getNumber()
web3.eth.call(Client,
'0x1a306890df22c0965b0b1515a8082f8301d3d18e',
'getNumber()', [], procedure(qty: BigInteger; err: IError)
begin
TThread.Synchronize(nil, procedure
begin
if Assigned(err) then
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0)
else
ShowMessage(qty.ToString);
@svanas
svanas / Unit1.pas
Last active October 1, 2023 13:31
Create a new web3 client for the Sepolia test net
var
Client: IWeb3;
procedure TForm1.FormCreate(Sender: TObject);
begin
Client := TWeb3.Create(Sepolia.SetRPC('https://sepolia.infura.io/v3/your-project-id'));
end;
@svanas
svanas / ArithValue.sol
Last active October 1, 2023 13:10
Increment and decrement operations using Solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract ArithValue {
uint number;
constructor () {
number = 100;
}
function setNumber(uint value) public {
@svanas
svanas / Unit1.pas
Last active October 1, 2023 12:46
Hello World Smart Contract
web3.eth.call(TWeb3.Create(
Sepolia.SetRPC( // Sepolia test net
'https://sepolia.infura.io/v3/your-project-id')), // RPC access to Sepolia
'0x643C9Db08aBE4D95e4F2Afc733F78b601b84007A', // smart contract address
'myFirstHelloWorld()', [], procedure(tup: TTuple; err: IError)
begin
TThread.Synchronize(nil, procedure
begin
if Assigned(err) then
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0)
@svanas
svanas / HelloWorld.sol
Last active October 1, 2023 12:37
Hello World Smart Contract
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract HelloWorld {
function myFirstHelloWorld() public pure returns (string memory) {
return 'Hello World!';
}
}
@svanas
svanas / Unit1.pas
Last active May 31, 2023 17:36
Generating an Ethereum-signed message signature in Delphi
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(
web3.eth.crypto.sign(
TPrivateKey('b5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7'),
'Hello, World!'
).ToHex
);
end;