Skip to content

Instantly share code, notes, and snippets.

Avatar

Stefan svanas

View GitHub Profile
@svanas
svanas / Unit1.pas
Last active Jul 14, 2022
Listen to swaps between two tokens on Balancer
View Unit1.pas
const client: IWeb3 = TWeb3.Create(
web3.Ethereum,
web3.eth.infura.endpoint(web3.Ethereum, INFURA_PROJECT_ID)
);
const task = web3.eth.balancer.v2.listen(
client,
procedure(
blockNo : BigInteger;
poolId : TBytes32;
@svanas
svanas / Unit1.pas
Last active Jul 12, 2022
Swap 100 USDC for WETH on Ethereum
View Unit1.pas
const client: IWeb3 = TWeb3.Create(
web3.Ethereum,
web3.eth.infura.endpoint(web3.Ethereum, INFURA_PROJECT_ID)
);
web3.eth.balancer.v2.swap(
client,
owner,
TSwapKind.GivenIn,
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
@svanas
svanas / ETH-XXX-2.sh
Last active Jan 20, 2022
Use the Nefertiti crypto bot and trade on all the ETH-XXX market pairs with a single click.
View ETH-XXX-2.sh
# 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 Jan 10, 2022
Listen on Blocknative's mempool WebSocket API
View Unit1.pas
var
Mempool: IMempool;
procedure TForm1.Button1Click(Sender: TObject);
begin
Mempool := TSgcMempool.Subscribe(
Mainnet, // ethereum main net
'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // your blocknative API key
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // address to watch
procedure(event: TJsonObject; err: IError) // continuous events (or a blocknative error)
View Unit1.pas
begin
var client: IWeb3 := TWeb3.Create('https://<your-node-name>.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);
@svanas
svanas / Unit1.pas
Last active Jan 29, 2022
setNumber()
View Unit1.pas
web3.eth.write(Client,
'b5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7', // from private key
'0x94863b36b2d245cdeb3686837fb81ebd78a18086', // to smart contract
'setNumber(uint256)', [143],
procedure(rcpt: ITxReceipt; err: IError) begin end);
@svanas
svanas / Unit1.pas
Last active Jan 29, 2022
incrementNumber()
View Unit1.pas
web3.eth.write(Client,
'b5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7', // from private key
'0x94863b36b2d245cdeb3686837fb81ebd78a18086', // to smart contract
'incrementNumber()', [],
procedure(rcpt: ITxReceipt; err: IError) begin end);
@svanas
svanas / Unit1.pas
Last active Jan 10, 2022
Create a new web3 client for the Ropsten test net
View Unit1.pas
var
Client: IWeb3;
procedure TForm1.FormCreate(Sender: TObject);
begin
Client := TWeb3.Create(Ropsten, 'https://ropsten.infura.io/v3/your-project-id');
end;
@svanas
svanas / Unit1.pas
Last active Jan 11, 2021
getNumber()
View Unit1.pas
web3.eth.call(Client,
'0x94863b36b2d245cdeb3686837fb81ebd78a18086',
'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);