ETH
Section
Mix.install(
[{:ethereumex, "~> 0.7.0"}],
force: true,
verbose: true,
config: [
ethereumex: [
# url: "https://ropsten.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
url: "https://rpc.api.moonbase.moonbeam.network/"
]
]
)
Mix.install/2 using /Users/lucas/Library/Caches/mix/installs/elixir-1.13.4-erts-12.3.1/6cab03e70af8d85910c1339492f17cb7
Resolving Hex dependencies...
Dependency resolution completed:
New:
certifi 2.9.0
ethereumex 0.7.1
hackney 1.18.1
httpoison 1.8.1
idna 6.1.1
jason 1.3.0
metrics 1.0.1
mimerl 1.2.0
parse_trans 3.3.1
poolboy 1.5.2
ssl_verify_fun 1.1.6
telemetry 1.1.0
unicode_util_compat 0.7.0
* Getting ethereumex (Hex package)
* Getting httpoison (Hex package)
* Getting jason (Hex package)
* Getting poolboy (Hex package)
* Getting telemetry (Hex package)
* Getting hackney (Hex package)
* Getting certifi (Hex package)
* Getting idna (Hex package)
* Getting metrics (Hex package)
* Getting mimerl (Hex package)
* Getting parse_trans (Hex package)
* Getting ssl_verify_fun (Hex package)
* Getting unicode_util_compat (Hex package)
===> Analyzing applications...
===> Compiling parse_trans
===> Analyzing applications...
===> Compiling mimerl
===> Analyzing applications...
===> Compiling metrics
===> Analyzing applications...
===> Compiling unicode_util_compat
===> Analyzing applications...
===> Compiling idna
===> Analyzing applications...
===> Compiling poolboy
===> Analyzing applications...
===> Compiling telemetry
==> jason
Compiling 10 files (.ex)
==> ssl_verify_fun
Compiling 7 files (.erl)
Generated ssl_verify_fun app
===> Analyzing applications...
===> Compiling certifi
===> Analyzing applications...
===> Compiling hackney
==> httpoison
Compiling 3 files (.ex)
==> ethereumex
Compiling 8 files (.ex)
Generated ethereumex app
:ok
Ethereumex.HttpClient.eth_get_transaction_by_hash(
"0xa04ade0eadfadcdb7b7384693c3af1638998574bb0802002dfeafcb6d7604d62"
)
{:ok,
%{
"accessList" => [],
"blockHash" => "0xf71f11c3ce88d23e55472baf317499fad28607c120e0eda6e5c347ef00500419",
"blockNumber" => "0x1ffa87",
"chainId" => "0x507",
"creates" => nil,
"from" => "0x73c7448760517e3e6e416b2c130e3c6db2026a1d",
"gas" => "0x6057a",
"gasPrice" => "0xb2d05e00",
"hash" => "0xa04ade0eadfadcdb7b7384693c3af1638998574bb0802002dfeafcb6d7604d62",
"input" => "0xd85d3d270000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002b72723570385f464a346c304b766a684374497a6d7866424e4e3355694e324376324d6c30387973396f6445000000000000000000000000000000000000000000",
"maxFeePerGas" => "0xc1b71080",
"maxPriorityFeePerGas" => "0x77359400",
"nonce" => "0x6",
"publicKey" => "0xc2efa7e9764f3329fa523fc913cd9e25b16a62bdef2e120d9c23cca8470aba07bc119dc207dd573f7d9ceb4e2a7cd61faaddb337a75b74d8fac4136c3b6136fb",
"r" => "0x332089c62bef1b5c55686f0324f407b2e24d706c932f9f4220d6d28512182bfe",
"raw" => "0xb8f502f8f282050706847735940084c1b710808306057a94d1e91a4bf55111dd3725e46a64cdbe7a2cc97d8a80b884d85d3d270000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002b72723570385f464a346c304b766a684374497a6d7866424e4e3355694e324376324d6c30387973396f6445000000000000000000000000000000000000000000c080a0332089c62bef1b5c55686f0324f407b2e24d706c932f9f4220d6d28512182bfea010edb6dd63da43ce7b54c53dd1437a9ce16964852a40880b68ebfffb04d9cd31",
"s" => "0x10edb6dd63da43ce7b54c53dd1437a9ce16964852a40880b68ebfffb04d9cd31",
"standardV" => "0x0",
"to" => "0xd1e91a4bf55111dd3725e46a64cdbe7a2cc97d8a",
"transactionIndex" => "0x0",
"type" => "0x2",
"v" => "0x0",
"value" => "0x0"
}}
{re, payload} = Ethereumex.HttpClient.eth_block_number()
{:ok, "0x202e09"}
基本API使用
defmodule Utils do
def hex_to_int(hex) do
hex
|> String.slice(2..-1)
|> String.to_integer(16)
end
end
{:module, Utils, <<70, 79, 82, 49, 0, 0, 6, ...>>, {:hex_to_int, 1}}
{re, payload} = Ethereumex.HttpClient.eth_block_number()
# Utils.hex_to_int(payload)
{:ok, "0x202e0b"}
Ethereumex.HttpClient.eth_get_block_by_number(payload, false)
{:ok,
%{
"author" => "0xeda33e2b5ffb97bb8b901b71b87e5791556fd46b",
"baseFeePerGas" => "0x3b9aca00",
"difficulty" => "0x0",
"extraData" => "0x",
"gasLimit" => "0xe4e1c0",
"gasUsed" => "0x8bd9b2",
"hash" => "0x52e7e33b34672bee4ed5071cf54dc870f8d48bf2d4f08ce97812fef04f4ccaf1",
"logsBloom" => "0x00000000000000000000000000010000000000000000100000000000000000000000000000000000000000000000000000000000800000000000000001200000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000010000000000000001000000000000000020000000000000000000000000000",
"miner" => "0xeda33e2b5ffb97bb8b901b71b87e5791556fd46b",
"number" => "0x202e0b",
"parentHash" => "0x3bbfa6682d1815efade7407897b9ec8ab40f6dd27cb2986f52298139f2a2b68c",
"receiptsRoot" => "0x7c469726f9ee0d9a8ed8a32248b8649f6ae90d4789b87c25bd808de10d688b52",
"sealFields" => ["0x0000000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000"],
"sha3Uncles" => "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size" => "0xe726",
"stateRoot" => "0x9ee6b2d432bf18b9797b1ea132f45808bb0578671b4b795eedf375e658b0c3ec",
"timestamp" => "0x62747f64",
"totalDifficulty" => "0x0",
"transactions" => ["0xf40776afa7a525b371cc636cfeb3168597ea051ada3f4708b81230ff4e844b13",
"0x9d62d7fb069ccd8cbdc4e19a8405caa70356c0f80bffc92c4967b9a6e79b6725",
"0x37be5fc5f1c3236a4ddfa0c416fb5b817a78b7a85f6d8b4ad85e733299b598bb",
"0x332f792ba1a43924f2ca553ebebc50513a1f12848258f889330ac89ab551639c",
"0x689f4b1a0630e28b732ffe8ae93a64850d1fbe693df242630766e970f532010e",
"0xab27cb764098cc66ca1c5dbf14c31009a9466b3cd8158b19920f459622778ec2",
"0xdccdafa5d4104573e292be5807e11ecb75ecdc8d40971eb2b254acbc25b4db87",
"0x4c1973213ea27176840abbd7ac0041837da319c430d4546bf23c8b29a8d46ccf",
"0x8c3d2633d63f85fda6154e39998d91b997fb157c136fb752bb99685d1a804647",
"0x63257000fe1a52e001161c15795f232741fc3598cb7013e8e7c6fc8962893c01",
"0x597f1aaf227dccfdb7f10e30e54261e1a9c92f8bc4d7e805a8c057b9cd959e97",
"0x187bc959aac9d0d8342a1a78dd09f986e096ea2b0f570126765afe371a3b1b22",
"0xb2f413bbe433e8506b360303f2a873e31fddc9d62cd915022970728a23b8698d",
"0xd039cdca4429e4cde8ab12a3cec603268956a43e8915c669d08e3718205fe79f",
"0x3fd5d091dadaaf500ebd8d91522970ae65133cb7a60dd031f783930914e98c6f",
"0xd102896e8cff24c3a0d16dab860757ecc1254653d7528b2c3e92b8397a0eda4e",
"0xf24b6d25241467a5488f6db819f4b70f7b7773e163db01c0f4f531fbafd84ac5",
"0x31d7b9579f916c272a0f50bd68279f08394cc7a953d5aba6cdc365050d3d77c2",
"0x81f4ed6527aaf8a943919b28b009e5074661c968212c7812c5f7b14bd96079f6",
"0x1ae61ecda25db9280225acb32d1f416a0f89ad88b2da700d0f4aa2b301636d76",
"0x5d96ac8335a8244a22d932ce909ba7151190867b9364650e730539fab80de877",
"0x790fe239266f3161527d6330e935d7959eb3e8fb496ee05aa8b6feda21fe15cf",
"0x575253d52c88634893578f53311b526c2a18abca2d50ad1ddcc4bdd650ac2ff7",
"0x82633d50b3cc2296881340d54ae7111b29a4ea706be8131ffef26acbed455a4e",
"0x0ec5b6d0ee028730732bc51e20aa917b3cbeb311b7f011dcef862cb0cfb3d33d",
"0x46c9c44bd956c4ab6e1a19b51b462c73fa1a1c914ea68cab1167faf351453735",
"0xfcd0d6c626561b4bec8b1de40613cb81afcfb9e10940c241e2c80f74c052d135",
"0xb4ff2da0c9064aaa950a9ba9537ee93a315d9cc42e8b03f4fb360ee2491a9dca",
"0xe79d34849652d21fbfd4848a61056e33fb2a954ffd3a4747371819369abfa708", ...],
"transactionsRoot" => "0x83fd7ad1716636b81bbf0aba5ac6b48faee7d19b2793e84fef00ba67d794b6b2",
"uncles" => []
}}
Ethereumex.HttpClient.eth_get_transaction_by_hash(
"0xb1605f0cca61569da236daf30209cc766a989186e3a5f8710af8725e15d6d15b"
)
{:ok, nil}
Ethereumex.HttpClient.eth_get_transaction_receipt(
"0x441c008ff96cbe95ca3b9889cf044c837b90e3001b9eba24fa430f6757a1c046"
)
{:ok, nil}
{:ok, balance} =
Ethereumex.HttpClient.eth_get_balance(
"0xC3A9d35BFFCb9E9363b5911A0e255743AA6A60Ab",
"latest"
)
Utils.hex_to_int(balance)
0
智能合约
Ethereumex.HttpClient.eth_gas_price()
{:ok, "0x3b9aca00"}
## check
Ethereumex.Config.rpc_url()
"https://rpc.api.moonbase.moonbeam.network/"