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 May 31, 2023 17:13
Listen to swaps between two tokens on Balancer
const client: IWeb3 = TWeb3.Create(
web3.eth.infura.endpoint(web3.Ethereum, INFURA_PROJECT_ID).Value
);
const task = web3.eth.balancer.v2.listen(
client,
procedure(
blockNo : BigInteger;
poolId : TBytes32;
tokenIn : TAddress;
@svanas
svanas / Unit1.pas
Last active May 31, 2023 17:16
Swap 100 USDC for WETH on Ethereum
const client: IWeb3 = TWeb3.Create(
web3.eth.infura.endpoint(web3.Ethereum, INFURA_PROJECT_ID).Value
);
web3.eth.balancer.v2.swap(
client,
owner,
TSwapKind.GivenIn,
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
@svanas
svanas / ETH-XXX-2.sh
Last active January 20, 2022 09:47
Use the Nefertiti crypto bot and trade on all the ETH-XXX market pairs with a single click.
# Trade on all the ETH-XXX market pairs.
# Written by Stefan van As <svanas AT runbox DOT com>
# Example: ./ETH-XXX-2.sh --exchange=Bittrex --price=0.05 --pushover-app-key=X --pushover-user-key=X
for i in "$@"
do
case $i in
--exchange=*)
EXCHANGE="${i#*=}"
shift # past argument=value
@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: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 / 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);