Skip to content

Instantly share code, notes, and snippets.

View svanas's full-sized avatar

Stefan svanas

View GitHub Profile
@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 / 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 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 / Unit2.pas
Last active February 7, 2023 14:53
ENS reverse lookup
TAddress.Create('0xa0400ba66b4fe0b13bb909abfd377596c02b6733').ToString(
TWeb3.Create(Ethereum.SetRPC('https://mainnet.infura.io/v3/your-project-id')),
procedure(str: string; err: IError)
begin
TThread.Synchronize(nil, procedure
begin
if Assigned(err) then
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0)
else
ShowMessage(str);
@svanas
svanas / Unit1.pas
Last active May 31, 2023 17:28
ENS resolve address
TAddress.FromName(TWeb3.Create(
Ethereum.SetRPC('https://mainnet.infura.io/v3/your-project-id')), // Ethereum mainnet
'thecoinoffering.eth', // Ethereum domain name
procedure(addr: TAddress; err: IError)
begin
TThread.Synchronize(nil, procedure
begin
if Assigned(err) then
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0)
else
@svanas
svanas / Unit1.pas
Last active May 31, 2023 17:33
Transferring ERC-20 tokens with Delphi
const ERC20 = TERC20.Create(TWeb3.Create(
Goerli.SetRPC('https://goerli.infura.io/v3/your-project-id')), // Goerli testnet
'0x45843aF56Aa1057eD1730cA5Ba3F709833900E77'); // TST smart contract address
try
ERC20.Transfer(
TPrivateKey('24622d680bb9d6d80c4d3fb4b4818e738de64b521948b1b1c85616eeeda54ee1'), // from private key
'0xaDDcedc01C1070bCE0aF7eb853845e7811EB649C', // to public key
1000000000000000, // 0.001 TST
procedure(hash: TTxHash; err: IError)
begin
@svanas
svanas / Unit1.pas
Last active May 31, 2023 17:34
Transferring Ether with Delphi
web3.eth.tx.sendTransaction(
TWeb3.Create(Ganache), // Ganache 2.7.1
TPrivateKey('24622d680bb9d6d80c4d3fb4b4818e738de64b521948b1b1c85616eeeda54ee1'), // from private key
'0xaDDcedc01C1070bCE0aF7eb853845e7811EB649C', // to public key
web3.eth.utils.toWei('0.01', ether).Value, // 0.01 ether
procedure(tx: TTxHash; err: IError)
begin
TThread.Synchronize(nil, procedure
begin
if Assigned(err) then
@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;
@svanas
svanas / Unit1.pas
Last active November 17, 2022 14:43
Get the totalSupply() of a token (that is not ether) on the Ethereum blockchain
const Client: IWeb3 = TWeb3.Create('https://mainnet.infura.io/v3/your-project-id');
web3.eth.call(Client, '0xB8c77482e45F1F44dE1745F52C74426C631bDD52', 'symbol()', [], procedure(tup: TTuple; err: IError)
begin
if Assigned(err) then
begin
TThread.Synchronize(nil, procedure
begin
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0)
end);
EXIT;
@svanas
svanas / Unit1.pas
Last active May 8, 2023 14:38
Get balance of Ethereum wallet from Delphi
web3.eth.getBalance(TWeb3.Create(Ganache), Edit1.Text, 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(web3.eth.utils.fromWei(qty, web3.eth.utils.ether) + ' ether');
end);
end);