-module(gleeth@rpc@methods). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/gleeth/rpc/methods.gleam"). -export([get_block_number/1, get_balance/2, call_contract/3, get_code/2, get_storage_at/4, get_chain_id/1, send_raw_transaction/2, get_transaction_count/3, get_gas_price/1, get_max_priority_fee/1, get_transaction/2, get_fee_history/4, get_transaction_receipt/2, parse_transaction_receipt/1, estimate_gas/5, get_logs/5]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Ethereum JSON-RPC method wrappers.\n" "\n" " Each public function in this module corresponds to a standard Ethereum\n" " JSON-RPC method (e.g. `eth_blockNumber`, `eth_getBalance`). Functions\n" " accept a `Provider` as their first argument and return a typed `Result`\n" " with `GleethError` on failure.\n" ). -file("src/gleeth/rpc/methods.gleam", 25). ?DOC( " Get the latest block number by calling `eth_blockNumber`.\n" "\n" " Returns the block number as a hex-encoded string.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let assert Ok(p) = provider.new(\"http://localhost:8545\")\n" " let assert Ok(block) = get_block_number(p)\n" " ```\n" ). -spec get_block_number(gleeth@provider:provider()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. get_block_number(Provider) -> gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_block_number, [] ). -file("src/gleeth/rpc/methods.gleam", 46). ?DOC( " Get the balance of an address by calling `eth_getBalance`.\n" "\n" " Queries at the `\"latest\"` block. Returns the balance in wei as a\n" " hex-encoded string.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let assert Ok(p) = provider.new(\"http://localhost:8545\")\n" " let assert Ok(balance) = get_balance(p, \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\")\n" " ```\n" ). -spec get_balance(gleeth@provider:provider(), binary()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. get_balance(Provider, Address) -> Params = [gleam@json:string(Address), gleam@json:string(<<"latest"/utf8>>)], gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_get_balance, Params ). -file("src/gleeth/rpc/methods.gleam", 71). ?DOC( " Execute a read-only contract call by calling `eth_call`.\n" "\n" " Sends a call object with the given contract address and ABI-encoded\n" " calldata, evaluated at the `\"latest\"` block. Returns the hex-encoded\n" " return data.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let assert Ok(p) = provider.new(\"http://localhost:8545\")\n" " let calldata = \"0x70a08231000000000000000000000000d8dA6BF26964aF9D7eEd9e03E53415D37aA96045\"\n" " let assert Ok(result) = call_contract(p, \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", calldata)\n" " ```\n" ). -spec call_contract(gleeth@provider:provider(), binary(), binary()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. call_contract(Provider, Contract_address, Data) -> Call_object = gleam@json:object( [{<<"to"/utf8>>, gleam@json:string(Contract_address)}, {<<"data"/utf8>>, gleam@json:string(Data)}] ), Params = [Call_object, gleam@json:string(<<"latest"/utf8>>)], gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_call, Params ). -file("src/gleeth/rpc/methods.gleam", 93). ?DOC( " Get the deployed bytecode at an address by calling `eth_getCode`.\n" "\n" " Returns `\"0x\"` for externally-owned accounts (EOAs).\n" ). -spec get_code(gleeth@provider:provider(), binary()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. get_code(Provider, Address) -> Params = [gleam@json:string(Address), gleam@json:string(<<"latest"/utf8>>)], gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_get_code, Params ). -file("src/gleeth/rpc/methods.gleam", 135). ?DOC( " Get the storage value at a specific slot in a contract by calling\n" " `eth_getStorageAt`.\n" "\n" " If `block` is an empty string it defaults to `\"latest\"`.\n" ). -spec get_storage_at(gleeth@provider:provider(), binary(), binary(), binary()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. get_storage_at(Provider, Address, Slot, Block) -> Block_param = case Block of <<""/utf8>> -> <<"latest"/utf8>>; _ -> Block end, Params = [gleam@json:string(Address), gleam@json:string(Slot), gleam@json:string(Block_param)], gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_get_storage_at, Params ). -file("src/gleeth/rpc/methods.gleam", 169). ?DOC( " Get the chain ID of the connected network by calling `eth_chainId`.\n" "\n" " Returns the chain ID as a hex-encoded string (e.g. `\"0x1\"` for mainnet).\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let assert Ok(p) = provider.new(\"http://localhost:8545\")\n" " let assert Ok(chain_id) = get_chain_id(p)\n" " ```\n" ). -spec get_chain_id(gleeth@provider:provider()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. get_chain_id(Provider) -> gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_chain_id, [] ). -file("src/gleeth/rpc/methods.gleam", 189). ?DOC( " Broadcast a signed raw transaction to the network by calling\n" " `eth_sendRawTransaction`.\n" "\n" " `raw_tx` should be the hex-encoded signed transaction (e.g. `\"0x02f873...\"`).\n" " Returns the transaction hash on success.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let assert Ok(p) = provider.new(\"http://localhost:8545\")\n" " let assert Ok(tx_hash) = send_raw_transaction(p, \"0x02f873...\")\n" " ```\n" ). -spec send_raw_transaction(gleeth@provider:provider(), binary()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. send_raw_transaction(Provider, Raw_tx) -> Params = [gleam@json:string(Raw_tx)], gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_send_raw_transaction, Params ). -file("src/gleeth/rpc/methods.gleam", 206). ?DOC( " Get the transaction count (nonce) for an address by calling\n" " `eth_getTransactionCount`.\n" "\n" " If `block` is an empty string it defaults to `\"pending\"`, which gives the\n" " next usable nonce.\n" ). -spec get_transaction_count(gleeth@provider:provider(), binary(), binary()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. get_transaction_count(Provider, Address, Block) -> Block_param = case Block of <<""/utf8>> -> <<"pending"/utf8>>; _ -> Block end, Params = [gleam@json:string(Address), gleam@json:string(Block_param)], gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_get_transaction_count, Params ). -file("src/gleeth/rpc/methods.gleam", 226). ?DOC( " Get the current gas price in wei by calling `eth_gasPrice`.\n" "\n" " Primarily useful for legacy (pre-EIP-1559) transactions.\n" ). -spec get_gas_price(gleeth@provider:provider()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. get_gas_price(Provider) -> gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_gas_price, [] ). -file("src/gleeth/rpc/methods.gleam", 240). ?DOC( " Get the suggested max priority fee per gas by calling\n" " `eth_maxPriorityFeePerGas`.\n" "\n" " Used when building EIP-1559 (Type 2) transactions.\n" ). -spec get_max_priority_fee(gleeth@provider:provider()) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. get_max_priority_fee(Provider) -> gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_max_priority_fee_per_gas, [] ). -file("src/gleeth/rpc/methods.gleam", 369). -spec nullable_string() -> gleam@dynamic@decode:decoder(binary()). nullable_string() -> gleam@dynamic@decode:one_of( {decoder, fun gleam@dynamic@decode:decode_string/1}, [gleam@dynamic@decode:success(<<""/utf8>>)] ). -file("src/gleeth/rpc/methods.gleam", 373). -spec transaction_decoder() -> gleam@dynamic@decode:decoder(gleeth@ethereum@types:transaction()). transaction_decoder() -> gleam@dynamic@decode:field( <<"hash"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Hash) -> gleam@dynamic@decode:optional_field( <<"blockNumber"/utf8>>, <<""/utf8>>, nullable_string(), fun(Block_number) -> gleam@dynamic@decode:optional_field( <<"blockHash"/utf8>>, <<""/utf8>>, nullable_string(), fun(Block_hash) -> gleam@dynamic@decode:optional_field( <<"transactionIndex"/utf8>>, <<""/utf8>>, nullable_string(), fun(Transaction_index) -> gleam@dynamic@decode:field( <<"from"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(From) -> gleam@dynamic@decode:optional_field( <<"to"/utf8>>, <<""/utf8>>, nullable_string(), fun(To) -> gleam@dynamic@decode:field( <<"value"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Value) -> gleam@dynamic@decode:field( <<"gas"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Gas) -> gleam@dynamic@decode:optional_field( <<"gasPrice"/utf8>>, <<""/utf8>>, nullable_string( ), fun( Gas_price ) -> gleam@dynamic@decode:optional_field( <<"maxFeePerGas"/utf8>>, <<""/utf8>>, nullable_string( ), fun( Max_fee_per_gas ) -> gleam@dynamic@decode:optional_field( <<"maxPriorityFeePerGas"/utf8>>, <<""/utf8>>, nullable_string( ), fun( Max_priority_fee_per_gas ) -> gleam@dynamic@decode:field( <<"input"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun( Input ) -> gleam@dynamic@decode:field( <<"nonce"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun( Nonce ) -> gleam@dynamic@decode:optional_field( <<"type"/utf8>>, <<""/utf8>>, nullable_string( ), fun( Transaction_type ) -> gleam@dynamic@decode:optional_field( <<"chainId"/utf8>>, <<""/utf8>>, nullable_string( ), fun( Chain_id ) -> gleam@dynamic@decode:field( <<"v"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun( V ) -> gleam@dynamic@decode:field( <<"r"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun( R ) -> gleam@dynamic@decode:field( <<"s"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun( S ) -> gleam@dynamic@decode:success( {transaction, Hash, Block_number, Block_hash, Transaction_index, From, To, Value, Gas, Gas_price, Max_fee_per_gas, Max_priority_fee_per_gas, Input, Nonce, Transaction_type, Chain_id, V, R, S} ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ). -file("src/gleeth/rpc/methods.gleam", 290). ?DOC( " Get a transaction by its hash by calling `eth_getTransactionByHash`.\n" "\n" " Returns a fully decoded `Transaction` record.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let assert Ok(p) = provider.new(\"http://localhost:8545\")\n" " let assert Ok(tx) = get_transaction(p, \"0xabc123...\")\n" " ```\n" ). -spec get_transaction(gleeth@provider:provider(), binary()) -> {ok, gleeth@ethereum@types:transaction()} | {error, gleeth@rpc@types:gleeth_error()}. get_transaction(Provider, Hash) -> Params = [gleam@json:string(Hash)], gleeth@rpc@response_utils:make_decoded_request( gleeth@provider:rpc_url(Provider), eth_get_transaction_by_hash, Params, transaction_decoder() ). -file("src/gleeth/rpc/methods.gleam", 467). -spec log_decoder() -> gleam@dynamic@decode:decoder(gleeth@ethereum@types:log()). log_decoder() -> gleam@dynamic@decode:field( <<"address"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Address) -> gleam@dynamic@decode:field( <<"topics"/utf8>>, gleam@dynamic@decode:list(nullable_string()), fun(Topics) -> gleam@dynamic@decode:field( <<"data"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Data) -> gleam@dynamic@decode:field( <<"blockNumber"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Block_number) -> gleam@dynamic@decode:field( <<"transactionHash"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Transaction_hash) -> gleam@dynamic@decode:field( <<"transactionIndex"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Transaction_index) -> gleam@dynamic@decode:field( <<"blockHash"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Block_hash) -> gleam@dynamic@decode:field( <<"logIndex"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Log_index) -> gleam@dynamic@decode:field( <<"removed"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_bool/1}, fun( Removed ) -> gleam@dynamic@decode:success( {log, Address, Topics, Data, Block_number, Transaction_hash, Transaction_index, Block_hash, Log_index, Removed} ) end ) end ) end ) end ) end ) end ) end ) end ) end ). -file("src/gleeth/rpc/methods.gleam", 491). -spec fee_history_decoder() -> gleam@dynamic@decode:decoder(gleeth@ethereum@types:fee_history()). fee_history_decoder() -> gleam@dynamic@decode:field( <<"oldestBlock"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Oldest_block) -> gleam@dynamic@decode:field( <<"baseFeePerGas"/utf8>>, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun(Base_fee_per_gas) -> gleam@dynamic@decode:field( <<"gasUsedRatio"/utf8>>, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_float/1} ), fun(Gas_used_ratio) -> gleam@dynamic@decode:optional_field( <<"reward"/utf8>>, [], gleam@dynamic@decode:list( gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_string/1} ) ), fun(Reward) -> gleam@dynamic@decode:success( {fee_history, Oldest_block, Base_fee_per_gas, Gas_used_ratio, Reward} ) end ) end ) end ) end ). -file("src/gleeth/rpc/methods.gleam", 257). ?DOC( " Get fee history for recent blocks by calling `eth_feeHistory`.\n" "\n" " - `block_count` - number of blocks to return (as a decimal integer)\n" " - `newest_block` - highest block (`\"latest\"`, `\"pending\"`, or a hex block\n" " number); defaults to `\"latest\"` when empty\n" " - `reward_percentiles` - percentiles of effective priority fees to include\n" " (e.g. `[25.0, 50.0, 75.0]`)\n" ). -spec get_fee_history( gleeth@provider:provider(), integer(), binary(), list(float()) ) -> {ok, gleeth@ethereum@types:fee_history()} | {error, gleeth@rpc@types:gleeth_error()}. get_fee_history(Provider, Block_count, Newest_block, Reward_percentiles) -> Newest = case Newest_block of <<""/utf8>> -> <<"latest"/utf8>>; _ -> Newest_block end, Params = [gleam@json:int(Block_count), gleam@json:string(Newest), gleam@json:array(Reward_percentiles, fun gleam@json:float/1)], gleeth@rpc@response_utils:make_decoded_request( gleeth@provider:rpc_url(Provider), eth_fee_history, Params, fee_history_decoder() ). -file("src/gleeth/rpc/methods.gleam", 511). -spec status_decoder() -> gleam@dynamic@decode:decoder(gleeth@ethereum@types:transaction_status()). status_decoder() -> gleam@dynamic@decode:then( {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Status_str) -> case Status_str of <<"0x1"/utf8>> -> gleam@dynamic@decode:success(success); <<"0x01"/utf8>> -> gleam@dynamic@decode:success(success); <<"0x0"/utf8>> -> gleam@dynamic@decode:success(failed); <<"0x00"/utf8>> -> gleam@dynamic@decode:success(failed); _ -> gleam@dynamic@decode:failure( failed, <<"TransactionStatus"/utf8>> ) end end ). -file("src/gleeth/rpc/methods.gleam", 431). -spec transaction_receipt_decoder() -> gleam@dynamic@decode:decoder(gleeth@ethereum@types:transaction_receipt()). transaction_receipt_decoder() -> gleam@dynamic@decode:field( <<"transactionHash"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Transaction_hash) -> gleam@dynamic@decode:field( <<"transactionIndex"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Transaction_index) -> gleam@dynamic@decode:field( <<"blockHash"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Block_hash) -> gleam@dynamic@decode:field( <<"blockNumber"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Block_number) -> gleam@dynamic@decode:field( <<"from"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(From) -> gleam@dynamic@decode:optional_field( <<"to"/utf8>>, <<""/utf8>>, nullable_string(), fun(To) -> gleam@dynamic@decode:field( <<"cumulativeGasUsed"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Cumulative_gas_used) -> gleam@dynamic@decode:field( <<"gasUsed"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Gas_used) -> gleam@dynamic@decode:optional_field( <<"contractAddress"/utf8>>, <<""/utf8>>, nullable_string( ), fun( Contract_address ) -> gleam@dynamic@decode:field( <<"logs"/utf8>>, gleam@dynamic@decode:list( log_decoder( ) ), fun( Logs ) -> gleam@dynamic@decode:field( <<"logsBloom"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun( Logs_bloom ) -> gleam@dynamic@decode:field( <<"status"/utf8>>, status_decoder( ), fun( Status ) -> gleam@dynamic@decode:field( <<"effectiveGasPrice"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun( Effective_gas_price ) -> gleam@dynamic@decode:success( {transaction_receipt, Transaction_hash, Transaction_index, Block_hash, Block_number, From, To, Cumulative_gas_used, Gas_used, Contract_address, Logs, Logs_bloom, Status, Effective_gas_price} ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ). -file("src/gleeth/rpc/methods.gleam", 308). ?DOC( " Get a transaction receipt by its hash by calling\n" " `eth_getTransactionReceipt`.\n" "\n" " Returns a fully decoded `TransactionReceipt` record including logs and\n" " status.\n" ). -spec get_transaction_receipt(gleeth@provider:provider(), binary()) -> {ok, gleeth@ethereum@types:transaction_receipt()} | {error, gleeth@rpc@types:gleeth_error()}. get_transaction_receipt(Provider, Transaction_hash) -> Params = [gleam@json:string(Transaction_hash)], gleeth@rpc@response_utils:make_decoded_request( gleeth@provider:rpc_url(Provider), eth_get_transaction_receipt, Params, transaction_receipt_decoder() ). -file("src/gleeth/rpc/methods.gleam", 325). ?DOC( " Parse a transaction receipt from a raw JSON-RPC response body.\n" "\n" " This is primarily intended for testing - it decodes the JSON string\n" " directly rather than making an RPC call.\n" ). -spec parse_transaction_receipt(binary()) -> {ok, gleeth@ethereum@types:transaction_receipt()} | {error, gleeth@rpc@types:gleeth_error()}. parse_transaction_receipt(Body) -> gleeth@rpc@response_utils:decode_rpc_response( Body, transaction_receipt_decoder() ). -file("src/gleeth/rpc/methods.gleam", 521). -spec build_optional_params(list({binary(), binary()})) -> list({binary(), gleam@json:json()}). build_optional_params(Pairs) -> case Pairs of [] -> []; [{Key, Value} | Rest] -> case Value of <<""/utf8>> -> build_optional_params(Rest); _ -> [{Key, gleam@json:string(Value)} | build_optional_params(Rest)] end end. -file("src/gleeth/rpc/methods.gleam", 108). ?DOC( " Estimate the gas required for a transaction by calling `eth_estimateGas`.\n" "\n" " Any parameter may be an empty string to omit it from the call object.\n" ). -spec estimate_gas( gleeth@provider:provider(), binary(), binary(), binary(), binary() ) -> {ok, binary()} | {error, gleeth@rpc@types:gleeth_error()}. estimate_gas(Provider, From, To, Value, Data) -> Transaction_params = build_optional_params( [{<<"from"/utf8>>, From}, {<<"to"/utf8>>, To}, {<<"value"/utf8>>, Value}, {<<"data"/utf8>>, Data}] ), Transaction_object = gleam@json:object(Transaction_params), gleeth@rpc@response_utils:make_string_request( gleeth@provider:rpc_url(Provider), eth_estimate_gas, [Transaction_object] ). -file("src/gleeth/rpc/methods.gleam", 534). -spec append_if_nonempty( list({binary(), gleam@json:json()}), binary(), binary() ) -> list({binary(), gleam@json:json()}). append_if_nonempty(Params, Key, Value) -> case Value of <<""/utf8>> -> Params; _ -> [{Key, gleam@json:string(Value)} | Params] end. -file("src/gleeth/rpc/methods.gleam", 545). -spec append_topics(list({binary(), gleam@json:json()}), list(binary())) -> list({binary(), gleam@json:json()}). append_topics(Params, Topics) -> case Topics of [] -> Params; _ -> [{<<"topics"/utf8>>, gleam@json:array(Topics, fun gleam@json:string/1)} | Params] end. -file("src/gleeth/rpc/methods.gleam", 335). ?DOC( " Get event logs matching a filter by calling `eth_getLogs`.\n" "\n" " `from_block` and `to_block` default to `\"latest\"` when empty. `address`\n" " and `topics` are omitted from the filter when empty.\n" ). -spec get_logs( gleeth@provider:provider(), binary(), binary(), binary(), list(binary()) ) -> {ok, list(gleeth@ethereum@types:log())} | {error, gleeth@rpc@types:gleeth_error()}. get_logs(Provider, From_block, To_block, Address, Topics) -> From_block_param = case From_block of <<""/utf8>> -> <<"latest"/utf8>>; _ -> From_block end, To_block_param = case To_block of <<""/utf8>> -> <<"latest"/utf8>>; _ -> To_block end, Filter_params = begin _pipe = [{<<"fromBlock"/utf8>>, gleam@json:string(From_block_param)}, {<<"toBlock"/utf8>>, gleam@json:string(To_block_param)}], _pipe@1 = append_if_nonempty(_pipe, <<"address"/utf8>>, Address), append_topics(_pipe@1, Topics) end, Filter_object = gleam@json:object(Filter_params), gleeth@rpc@response_utils:make_decoded_request( gleeth@provider:rpc_url(Provider), eth_get_logs, [Filter_object], gleam@dynamic@decode:list(log_decoder()) ).