Skip to main content
Glama
ethereum.cpython-313.pyc11.7 kB
� t�h���x�SSKrSSKrSSKrSSKJr SSKJr SSKJr \R"\ 5r "SS5r g)�N)�Web3)�Account)�TransactionNotFoundc�r�\rSrSrSrSrSrSrSSjrSSjr S r S r S r S r S rSSjrSrSrSrg)�EthereumClient� zEthereum blockchain clientc�,�[R"SS5Ul[[R"UR55UlUR R 5(d[RS5 g[RS5 g)N�ETHEREUM_RPC_URLzhttps://cloudflare-eth.comz%Failed to connect to Ethereum networkzConnected to Ethereum network) �os�getenv�rpc_urlr� HTTPProvider�w3� is_connected�logger�error�info)�selfs �)c:\ONEDeFi\defimcp\blockchain\ethereum.py�__init__�EthereumClient.__init__ s`���y�y�!3�5Q�R�� ��t�(�(����6�7����w�w�#�#�%�%� �L�L�@� A� �K�K�7� 8�c ��URRRU5nURRUS5n[ U5$![ a.n[ RSUS[ U535 SnAgSnAff=f)zGet ETH balance for address�etherzFailed to get balance for z: N�0)r�eth� get_balance�from_wei�str� Exceptionrr)r�address� balance_wei� balance_eth�es rr�EthereumClient.get_balancesq�� ��'�'�+�+�1�1�'�:�K��'�'�*�*�;��@�K��{�#� #��� � �L�L�5�g�Y�b��Q���I� J��� �s�A A� B�$B�Bc��SSSS./SSSS./SS .S/S S S S./SS ./nURRRX#S 9nURR U5R 5nURR 5R 5nUSU-- n[U5$![a+n[RS[U535 SnAgSnAff=f)zGet ERC20 token balanceT�_ownerr!)�name�type� balanceOf�balance�uint256�function)�constant�inputsr(�outputsr)�decimals��uint8�r!�abirzFailed to get token balance: Nr) rr�contract� functionsr*�callr1rr rr) r�wallet_address� token_address� erc20_abir6r+r1�formatted_balancer$s r�get_token_balance� EthereumClient.get_token_balance#s��� �!�$,�i�@�A�#�%.� �B�C�"� �!��"�%'��9�:�"� � �I��w�w�{�{�+�+�M�+�Q�H��(�(�2�2�>�B�G�G�I�G��)�)�2�2�4�9�9�;�H� '�2��>� :� ��(�)� )��� � �L�L�8��Q���A� B��� �s�B"B%�% C�/!C�CNc ��[R"SUR535nU(d[R SU35 gUR R RU5nUR R RnUcKUR R RUUU[U[5(a [U5OUS.5nUU[U[5(a [U5OUUUUSS .n UR R RR!X�5n UR R R#U R$5n [R'S U R)535 U R)5$![a.n [RS[U 5S35 SnSn A N�Sn A ff=f![a+n [R S [U 535 Sn A gSn A ff=f) zSend transaction� PRIVATE_KEY_zPrivate key not found for N)�from�to�data�value�Gas estimation failed: z, using default�@ �)�noncerBrD�gas�gasPricerC�chainIdzTransaction sent: zTransaction failed: )r r �upperrrrr�get_transaction_count� gas_price� estimate_gas� isinstancer�intr �warning�account�sign_transaction�send_raw_transaction�rawTransactionr�hex) rr9� to_addressrCrDrI� private_keyrHrNr$� transaction� signed_txn�tx_hashs r�send_transaction�EthereumClient.send_transaction@s���0 ��)�)�l�>�3G�3G�3I�2J�$K�L�K��� � �9�.�9I�J�K���G�G�K�K�5�5�n�E�E���� � �-�-�I��{� !��'�'�+�+�2�2� .�(� $�/9�%��/E�/E��U��5� 4��C�� �'1�%��'=�'=��U��5��%����K������,�,�=�=�k�W�J��g�g�k�k�6�6�z�7P�7P�Q�G� �K�K�,�W�[�[�]�O�<� =��;�;�=� ��-!�!��N�N�%<�S��V�H�O�#T�U� �C��!��0� � �L�L�/��A��x�8� 9��� �sK�AG� AG�A F�B=G� G�$$G �G� G�G� H �!H�H c�4�URRRXS9nURURUR UR R5S.$![a+n[RS[U535 SnAgSnAff=f)z!Wait for transaction confirmation)�timeout)�status� block_number�gas_used�transaction_hashz#Failed to get transaction receipt: N) rr�wait_for_transaction_receiptra� blockNumber�gasUsed�transactionHashrWr rrr)rr\r`�receiptr$s rre�+EthereumClient.wait_for_transaction_receiptts��� ��g�g�k�k�>�>�w�>�X�G�!�.�.� '� 3� 3�#�O�O�$+�$;�$;�$?�$?�$A� � ��� � �L�L�>�s�1�v�h�G� H��� �s�AA"�" B�,!B�Bc��URRRU5nURS:XaSOSURUR URRR UR- S.$![a SSS.s$[a9n[RS[U535 S [U5S .sS nA$S nAff=f) zGet transaction statusrG� confirmed�failed)rarbrc� confirmations�pendingr)rarnz"Failed to get transaction status: �unknown)rarN) rr�get_transaction_receiptrarfrgrbrr rrr)rr\rir$s r�get_transaction_status�%EthereumClient.get_transaction_status�s��� :��g�g�k�k�9�9�'�B�G�)0���1�)<�+�(� '� 3� 3�#�O�O�!%�����!9�!9�G�<O�<O�!O� � ��#� =�'�!�<� <�� :� �L�L�=�c�!�f�X�F� G�'�#�a�&�9� 9�� :�s$�A<A?�?C� C�.C �C� Cc��URRRU/S9n[URUS5nU"U6R 5nU$![ a+n[RS[U535 SnAgSnAff=f)zEncode function call data)r5r(z Failed to encode function call: N�0x) rrr6�getattrr7�_encode_transaction_datar rrr)rr5�argsr6r-� encoded_datar$s r�encode_function_call�#EthereumClient.encode_function_call�s}�� ��w�w�{�{�+�+���+�6�H��x�1�1�3�v�;�?�H�#�T�?�C�C�E�L�� ��� � �L�L�;�C��F�8�D� E��� �s�AA� B �!B�B c��URRRS5nUR$![aIn[ R S[U535 [[R"55sSnA$SnAff=f)z Get current blockchain timestamp�latestz!Failed to get current timestamp: N) rr� get_block� timestampr rrrrQ�time)r� latest_blockr$s r�get_current_timestamp�$EthereumClient.get_current_timestamp�sd�� $��7�7�;�;�0�0��:�L��)�)� )��� $� �L�L�<�S��V�H�E� F��t�y�y�{�#� #�� $�s�03� B�>B�;B�Bc��URRR$![a+n[R S[ U535 SnAgSnAff=f)zGet current gas pricezFailed to get gas price: NlH/P)rrrNr rrr�rr$s r� get_gas_price�EthereumClient.get_gas_price�sF�� ��7�7�;�;�(�(� (��� � �L�L�4�S��V�H�=� >��� ���"� A�!A�Ac��URRRU5$![a+n[R S[ U535 SnAgSnAff=f)zEstimate gas for transactionrENrF)rrrOr rrr)rrZr$s rrO�EthereumClient.estimate_gas�sK�� ��7�7�;�;�+�+�K�8� 8��� � �L�L�2�3�q�6�(�;� <��� ���$'� A�!A�Ac�L�URRRXS9n[URU5nU(aU"U6R 5nU$U"5R 5nU$![ a+n[RS[U535 SnAgSnAff=f)z"Call a read-only contract functionr4zContract call failed: N) rrr6rvr7r8r rrr) r�contract_addressr5� function_namerxr6r-�resultr$s r�call_contract_function�%EthereumClient.call_contract_function�s��� ��w�w�{�{�+�+�4D�+�N�H��x�1�1�=�A�H��!�4��-�-�/���M�"����*���M��� � �L�L�1�#�a�&��:� ;��� �s�AA.�A.�. B#�8!B�B#c��URRR$![a+n[R S[ U535 SnAgSnAff=f)zGet current block numberzFailed to get block number: Nr)rrrbr rrrr�s r�get_block_number�EthereumClient.get_block_number�sF�� ��7�7�;�;�+�+� +��� � �L�L�7��A��x�@� A��� �r�c��URRRU5$![a+n[R S[ U535 SnAgSnAff=f)zGet transaction detailszFailed to get transaction: N)rr�get_transactionr rrr)rr\r$s rr��EthereumClient.get_transaction�sK�� ��7�7�;�;�.�.�w�7� 7��� � �L�L�6�s�1�v�h�?� @��� �r�)r r)rurN)i,)N)�__name__� __module__� __qualname__�__firstlineno__�__doc__rrr=r]rerrrzr�r�rOr�r�r��__static_attributes__�rrrr sG��$� 9� ��:2�h �:�" �$����"�rr) r �loggingr��web3r� eth_accountr�web3.exceptionsr� getLoggerr�rrr�rr�<module>r�s3�� �� ���/� � � �8� $��T�Tr

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JMadhan1/OneDefi-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server