svanas / delphereum

web3 implementation for the Delphi programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hi,guru, SgcWebSockets thing blocked my way in https://svanas.medium.com/delphi-and-the-ethereum-dark-forest-5b430da3ad93 .

gneowing opened this issue · comments

Hi,guru, in https://svanas.medium.com/delphi-and-the-ethereum-dark-forest-5b430da3ad93 .
The SgcWebSockets thing blocked my way.
So, just install the trial version form https://www.esegece.com/websockets/download?

I installed the package and build then run .
An exception poped:
Could not load SSL library.
PATH
VERSION
METHODS "Failed to load libeay32.dll."'.

commented

Yes, you can download the trial version. I should probably make that more clear in the article.

commented

I installed the package and build then run . An exception poped: Could not load SSL library.

You can download the OpenSSL binaries here: https://github.com/IndySockets/OpenSSL-Binaries

Please download OpenSSL version 1.0.2u (aka the latest version supported by the Indy project).

Got it. Thanks.

Hi, guru
I downloaded the OpenSSL and copied files.
Now the APP is in no-response state after running my code lines.
For "Mainnet" is not defined in your original code, I tried "Ethereum“.
2023-05-17 092323
And finally I changed the "Mainnet" to "ChainMainnet" , but still no-response.

"
ChainMainnet: TChain = (
Id : 1;
Name : 'Ethereum';
Symbol : 'ETH';
TxType : 2;
RPC : ('https://mainnet.infura.io/v3/<MY_API_KEY>','');
BlockExplorer: 'https://etherscan.io';
TokenList : 'https://tokens.coingecko.com/uniswap/all.json'
"

The code lines:
procedure TFormTest.Button_Check_USDC_MemPool_Click(Sender: TObject);
var
Mempool: IMempool;
str_item:string;
a_ctrl:TControl;
begin
a_ctrl := TControl(Sender);
str_item := a_ctrl.Name + ' ';
//
Mempool := TSgcMempool.Subscribe(
ChainMainnet, //Mainnet, // ethereum main net
STR_API_KEY_NATIVE_BLOCK, // your blocknative API key
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // address to watch
procedure(event: TJsonObject; err: IError) // continuous events (or a blocknative error)
begin
var tx := web3.eth.blocknative.mempool.getTransaction(event);
if Assigned(tx) then
TThread.Synchronize(nil, procedure
begin
str_item := 'Pass! ' + str_item + tx.ToString;
SyncLogInMemo(self.Memo_Log_,str_item,True);
end);
end,
procedure(err: IError) // non-blocknative-error handler (probably a socket error)
begin
TThread.Synchronize(nil, procedure
begin
str_item := 'Fail! ' + str_item + err.Message;
SyncLogInMemo(self.Memo_Log_,str_item,True);
end);
end,
procedure
begin
// connection closed
str_item := 'Done! ' + str_item;
SyncLogInMemo(self.Memo_Log_,str_item,True);
end);
end;

commented

I changed the "Mainnet" to "ChainMainnet", but still no-response.

As a general rule, there is no good reason to introduce a new TChain unless you need to connect to a new chain Id that Delphereum doesn't know about.

" ChainMainnet: TChain = ( Id : 1; Name : 'Ethereum'; Symbol : 'ETH'; TxType : 2; RPC : ('https://mainnet.infura.io/v3/<MY_API_KEY>',''); BlockExplorer: 'https://etherscan.io'; TokenList : 'https://tokens.coingecko.com/uniswap/all.json' "

This should work for you Ethereum.SetRPC('https://mainnet.infura.io/v3/<MY_API_KEY>')

var Mempool: IMempool

If this variable is not global then it will go out of scope as soon as execution exits your procedure. When an interface goes out of scope and there aren't any other references to it, it gets destroyed automatically. In other words: your mempool object dies almost immediately.

STR_API_KEY_NATIVE_BLOCK

You did replace STR_API_KEY_NATIVE_BLOCK with your blocknative API key and MY_API_KEY with your Infura API key, did you not?

commented

One more thing. Here is a working example on how to use Delphereum with WebSockets. I suggest you try this example first.

Hi, guru
I git pulled the latest delphereum then modified my code according to your instruction and still got a no-reponse APP.
Then,I git pulled https://github.com/svanas/PubSub, builded and got a no-reponse APP too.
And, I applied API KEY from infura.
There is something wrong in https://github.com/svanas/PubSub if applying alchemy ones.

The modified code:
procedure TFormTest.Button_Check_USDC_MemPool_Click(Sender: TObject);
var
str_item:string;
a_ctrl:TControl;
begin
a_ctrl := TControl(Sender);
str_item := a_ctrl.Name + ' ';

Mempool := TSgcMempool.Subscribe( // 1) now it is global var
MyMainnet, // 2) it equals Ethereum.SetRPC(URL_MY_API_MAINNET) and the const URL_MY_API_MAINNET's value is from "mainnet.infura.io"
MY_API_NATIVE_BLOCK, // 3) yes, it is my blocknative API key, definitely , const MY_API_NATIVE_BLOCK : string = 'f8XXXXXX-XXXX-XX01-XXX4-6XXXXXXXXXX3'
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // address to watch
procedure(event: TJsonObject; err: IError) // continuous events (or a blocknative error)
begin
var tx := web3.eth.blocknative.mempool.getTransaction(event);
if Assigned(tx) then
TThread.Synchronize(nil, procedure
begin
str_item := 'Pass! ' + str_item + tx.ToString;
SyncLogInMemo(self.Memo_Log
,str_item,True);
end);
end,
procedure(err: IError) // non-blocknative-error handler (probably a socket error)
begin
TThread.Synchronize(nil, procedure
begin
str_item := 'Fail! ' + str_item + err.Message;
SyncLogInMemo(self.Memo_Log_,str_item,True);
end);
end,
procedure
begin
// connection closed
str_item := 'Done! ' + str_item;
SyncLogInMemo(self.Memo_Log_,str_item,True);
end);
end;

commented

Hi, guru I git pulled the latest delphereum then modified my code according to your instruction and still got a no-reponse APP

I am unsure what is wrong with your code, but I just tried this tutorial word-by-word and it works. I suggest you use the example from the tutorial.