基于区块链的毕业设计Ethereumex – 以太坊
本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计Ethereumex – 以太坊 是一篇很好的国外资料
Ethereumex
以太坊eth“>
Elixir JSON-RPC client for the Ethereum blockchain
Check out the documentation here.
Installation
Add Ethereumex to your mix.exs
dependencies:
- Add
ethereumex
to your list of dependencies inmix.exs
:
def deps do [{:ethereumex, "~> 0.6.4"}] end
- Ensure
ethereumex
is started before your application:
def application do [applications: [:ethereumex]] end
Configuration
In config/config.exs
, add Ethereum protocol host params to your config file
config :ethereumex, url: "http://localhost:8545"
You can also configure the HTTP
request timeout for requests sent to the Ethereum JSON-RPC (you can also overwrite this configuration in opts
used when calling the client). By default http requests use no pools, if you want to use hackney default http request pool:
config :ethereumex, http_options: [timeout: 8000, recv_timeout: 5000, hackney: [pool: :default]]
:timeout – timeout to establish a connection, in milliseconds. Default is 8000 :recv_timeout – timeout used when receiving a connection. Default is 5000
If you want to use IPC you will need to set a few things in your config.
First, specify the :client_type
:
config :ethereumex, client_type: :ipc
This will resolve to :http
by default.
Second, specify the :ipc_path
:
config :ethereumex, ipc_path: "/path/to/ipc"
If you want to count the number of RPC calls per RPC method or overall, you can attach yourself to executed telemetry events. There are two events you can attach yourself to: [:ethereumex]
# has RPC method name in metadata Emitted event: {:event, [:ethereumex], %{counter: 1}, %{method_name: "method_name"}}
or more granular [:ethereumex, <rpc_method>]
# %{} metadata Emitted event: {:event, [:ethereumex, :method_name_as_atom], %{counter: 1}, %{}}
Each event caries a single ticker that you can pass into your counters (like Statix.increment/2
). Be sure to add :telemetry as project dependency.
The IPC client type mode opens a pool of connection workers (default is 5 and 2, respectively). You can configure the pool size.
config :ethereumex, ipc_worker_size: 5, ipc_max_worker_overflow: 2, ipc_request_timeout: 60_000
Usage
Available methods:
- web3_clientVersion
- web3_sha3
- net_version
- net_peerCount
- net_listening
- eth_protocolVersion
- eth_syncing
- eth_coinbase
- eth_mining
- eth_hashrate
- eth_gasPrice
- eth_accounts
- eth_blockNumber
- eth_getBalance
- eth_getStorageAt
- eth_getTransactionCount
- eth_getBlockTransactionCountByHash
- eth_getBlockTransactionCountByNumber
- eth_getUncleCountByBlockHash
- eth_getUncleCountByBlockNumber
- eth_getCode
- eth_sign
- eth_sendTransaction
- eth_sendRawTransaction
- eth_call
- eth_estimateGas
- eth_getBlockByHash
- eth_getBlockByNumber
- eth_getTransactionByHash
- eth_getTransactionByBlockHashAndIndex
- eth_getTransactionByBlockNumberAndIndex
- eth_getTransactionReceipt
- eth_getUncleByBlockHashAndIndex
- eth_getUncleByBlockNumberAndIndex
- eth_getCompilers
- eth_compileLLL
- eth_compileSolidity
- eth_compileSerpent
- eth_newFilter
- eth_newBlockFilter
- eth_newPendingTransactionFilter
- eth_uninstallFilter
- eth_getFilterChanges
- eth_getFilterLogs
- eth_getLogs
- eth_getProof
- eth_getWork
- eth_submitWork
- eth_submitHashrate
- db_putString
- db_getString
- db_putHex
- db_getHex
- shh_post
- shh_version
- shh_newIdentity
- shh_hasIdentity
- shh_newGroup
- shh_addToGroup
- shh_newFilter
- shh_uninstallFilter
- shh_getFilterChanges
- shh_getMessages
IpcClient
You can follow along with any of these examples using IPC by replacing HttpClient
with IpcClient
.
Examples
iex> Ethereumex.HttpClient.web3_client_version {:ok, "Parity//v1.7.2-beta-9f47909-20170918/x86_64-macos/rustc1.19.0"} # Using the url option will overwrite the configuration iex> Ethereumex.HttpClient.web3_client_version(url: "http://localhost:8545") {:ok, "Parity//v1.7.2-beta-9f47909-20170918/x86_64-macos/rustc1.19.0"} iex> Ethereumex.HttpClient.web3_sha3("wrong_param") {:error, %{"code" => -32602, "message" => "Invalid params: invalid format."}} iex> Ethereumex.HttpClient.eth_get_balance("0x407d73d8a49eeb85d32cf465507dd71d507100c1") {:ok, "0x0"}
Note that all method names are snakecases, so, for example, shh_getMessages method has corresponding Ethereumex.HttpClient.shh_get_messages/1 method. Signatures can be found in Ethereumex.Client.Behaviour. There are more examples in tests.
eth_call example – Read only smart contract calls
In order to call a smart contract using the JSON-RPC interface you need to properly hash the data attribute (this will need to include the contract method signature along with arguments if any). You can do this manually or use a hex package like ABI to parse your smart contract interface or encode individual calls.
defp deps do [ ... {:ethereumex, "~> 0.6.3"}, {:ex_abi, "~> 0.4.0"} ... ] end
Now load the abi and pass the method signature. Note that the address needs to be converted to bytes
address = "0x123" |> String.slice(2..-1) |> Base.decode16(case: :mixed) contract_address = "0x432" abi_encoded_data = ABI.encode("balanceOf(address)", [address]) |> Base.encode16(case: :lower)
Now you can use eth_call to execute this smart contract command:
balance_bytes = Ethereumex.HttpClient.eth_call(%{ data: "0x" <> abi_encoded_data, to: contract_address })
To convert the balance into an integer:
balance_bytes |> String.slice(2..-1) |> Base.decode16!(case: :lower) |> TypeDecoder.decode_raw([{:uint, 256}]) |> List.first
Custom requests
Many Ethereum protocol implementations support additional JSON-RPC API methods. To use them, you should call Ethereumex.HttpClient.request/3 method.
For example, let’s call parity’s personal_listAccounts method.
iex> Ethereumex.HttpClient.request("personal_listAccounts", [], []) {:ok, ["0x71cf0b576a95c347078ec2339303d13024a26910", "0x7c12323a4fff6df1a25d38319d5692982f48ec2e"]}
Batch requests
To send batch requests use Ethereumex.HttpClient.batch_request/1 or batch_request/2 method.
requests = [ {:web3_client_version, []}, {:net_version, []}, {:web3_sha3, ["0x68656c6c6f20776f726c64"]} ] Ethereumex.HttpClient.batch_request(requests) { :ok, [ "Parity//v1.7.2-beta-9f47909-20170918/x86_64-macos/rustc1.19.0", "42", "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad" ] }
Built on Ethereumex
If you are curious what others are building with ethereumex, you might want to take a look at these projects:
-
exw3 – A high-level contract abstraction and other goodies similar to web3.js
-
eth – Ethereum utilities for Elixir.
-
eth_contract – A set of helper methods for calling ETH Smart Contracts via JSON RPC.
Contributing
- Fork it!
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Author
Ayrat Badykov (@ayrat555)
License
Ethereumex is released under the MIT License.
以太坊eth示例-只读智能合约调用贡献
作者混合exs:
以太坊eth区块链blockchain的Elixir JSON-RPC客户端
请查看此处的文档。
作者混合exs:
将以太坊eth添加到混合exs依赖项:
- 确保在应用程序之前启动以太坊eth:
def deps do [{:ethereumex, "~> 0.6.4"}] end
- web3u clientVersion
def application do [applications: [:ethereumex]] end
Configuration
在配置中/配置exs,将以太坊eth协议主机参数添加到配置文件
config :ethereumex, url: "http://localhost:8545"
您还可以为发送到以太坊ethJSON-RPC的请求配置HTTP请求超时(您还可以在调用客户端时使用的opts中覆盖此配置)。默认情况下,http请求不使用池,如果您想使用hackney默认http请求池:
config :ethereumex, http_options: [timeout: 8000, recv_timeout: 5000, hackney: [pool: :default]]
:timeout-建立连接的超时,以毫秒为单位。默认值为8000:recv_timeout-接收连接时使用的超时。默认值为5000
如果您想使用IPC,您需要在配置中设置一些内容。
首先,指定:client_type:
config :ethereumex, client_type: :ipc
这将默认解析为:http。
其次,指定:ipcu路径:
config :ethereumex, ipc_path: "/path/to/ipc"
如果要计算每个RPC方法或总体的RPC调用数,可以将自己附加到已执行的遥测事件。有两个事件是您可以自己依附的两个事件:一是[:以太以太(以太)以太(以太)以太(RPC)方法名在元数据中有RPC方法名称的事件发生:事件:{:事件,[:以太以太以太],%{counter:1},{方法_名称:”方法_名称“名字”}
或更具颗粒性的[:以太以太以太以太以太以太为以太以太以太以太以太以太为金,并与lt;RPC(u)方法方法>;gt;[35;35{{以利亚以太以利亚以太以太以太以太以太以太以太以太以太以太以太以太以太以太以太以太以p>每个事件都有一个单一的股票代码,你可以把它放到你的柜台(比如统计增量/2). 一定要添加:telemetry作为项目依赖项。
IPC客户端类型模式打开一个连接工作者池(默认值分别为5和2)。您可以配置池大小。
使用IPC将HttpClient替换为IpcClient,您可以使用这些示例中的任何一个。
config :ethereumex, ipc_worker_size: 5, ipc_max_worker_overflow: 2, ipc_request_timeout: 60_000
Usage
Available methods:
- web3u sha3
- net_版本
- 网络监听
- eth协议版本
- 以太币同步ethu getBlockTransactionCountByNumber
- ethu getTransactionByHash
- ethu getTransactionByBlockHashAndIndex
- ethu getTransactionByBlockNumberAndIndex
- ethu getTransactionReceipt
- ethu getUncleByBlockHashAndIndex
- ethu getcompilerl该公司编译了一家名为“爱特”的公司,该公司的编译器将继续在该公司的一个新的过滤器中,对该公司的新过滤器进行了新的过滤,并对该公司新设的过滤器进行了严格的过滤。子工作
- eth_accounts
- 该公司提交了该公司的专利权,并将该公司的专利权转让给了该公司。该公司将该公司的专利权转让给了该公司。该公司将把该公司的数个数进了该公司的一个数。该公司在该公司的上市后,该公司在该公司的上市后,该公司的上市后,该公司的上市后,该公司的版本在该公司的版本上,该公司的版本在该公司版本上,李>
- 该公司的新身份
- eth_getStorageAt
- eth_getTransactionCount
- eth_getBlockTransactionCountByHash
- eth_getBlockTransactionCountByNumber
- eth_getUncleCountByBlockHash
- eth_getUncleCountByBlockNumber
- eth_getCode
- eth_sign
- eth_sendTransaction
- eth_sendRawTransaction
- eth_call
- eth_estimateGas
- eth_getBlockByHash
- eth_getBlockByNumber
- eth_getTransactionByHash
- eth_getTransactionByBlockHashAndIndex
- eth_getTransactionByBlockNumberAndIndex
- shh
- shh的shh
- u新过滤器
- shh_卸载过滤器
- shhu getFilterChanges
- shhu getMessages
- exw3-一个高级合同抽象和其他类似web3.js的好东西
- eth-用于Elixir的以太坊eth实用程序。
- eth_contract-通过JSON RPC调用eth智能合约的一组助手方法。用叉子叉!
- 创建功能分支(git checkout-b my new feature)
- 提交更改(git Commit-am’Add some feature’)
- 推送到分支(git Push origin my new feature)
- 创建新请求
- eth_getLogs
- eth_getProof
- eth_getWork
- eth_submitWork
- eth_submitHashrate
- db_putString
- db_getString
- db_putHex
- db_getHex
- shh_post
- shh_version
- shh_newIdentity
- shh_hasIdentity
- shh_newGroup
- shh_addToGroup
- shh_newFilter
- shh_uninstallFilter
- shh_getFilterChanges
- shh_getMessages
IpcClient
请注意,所有方法名称都是蛇形格,因此,例如,shhu getMessages方法具有相应的Ethereumex.HttpClient.shh_获取消息/1方法。签名可以在以太坊eth客户端行为. 测试中有更多的例子。
Examples
iex> Ethereumex.HttpClient.web3_client_version {:ok, "Parity//v1.7.2-beta-9f47909-20170918/x86_64-macos/rustc1.19.0"} # Using the url option will overwrite the configuration iex> Ethereumex.HttpClient.web3_client_version(url: "http://localhost:8545") {:ok, "Parity//v1.7.2-beta-9f47909-20170918/x86_64-macos/rustc1.19.0"} iex> Ethereumex.HttpClient.web3_sha3("wrong_param") {:error, %{"code" => -32602, "message" => "Invalid params: invalid format."}} iex> Ethereumex.HttpClient.eth_get_balance("0x407d73d8a49eeb85d32cf465507dd71d507100c1") {:ok, "0x0"}
为了使用JSON-RPC接口调用智能协定,您需要正确地散列数据属性(这需要包括协定方法签名以及参数(如果有的话))。您可以手动执行此操作,也可以使用像ABI这样的十六进制包来解析智能合约接口或对单个调用进行编码。
eth_call example – Read only smart contract calls
现在加载abi并传递方法签名。请注意,地址需要转换为字节
defp deps do [ ... {:ethereumex, "~> 0.6.3"}, {:ex_abi, "~> 0.4.0"} ... ] end
现在您可以使用ethu调用来执行此智能合约命令:
address = "0x123" |> String.slice(2..-1) |> Base.decode16(case: :mixed) contract_address = "0x432" abi_encoded_data = ABI.encode("balanceOf(address)", [address]) |> Base.encode16(case: :lower)
将余额转换为整数:
balance_bytes = Ethereumex.HttpClient.eth_call(%{ data: "0x" <> abi_encoded_data, to: contract_address })
许多以太坊eth协议实现都支持其他JSON-RPC API方法。要使用它们,你应该打电话以太坊eth.HttpClient.request/3方法。
balance_bytes |> String.slice(2..-1) |> Base.decode16!(case: :lower) |> TypeDecoder.decode_raw([{:uint, 256}]) |> List.first
Custom requests
例如,让我们调用parity的personalu listAccounts方法。
要发送批处理请求,请使用Ethereumex.HttpClient.batch_请求/1或批处理请求/2方法。
iex> Ethereumex.HttpClient.request("personal_listAccounts", [], []) {:ok, ["0x71cf0b576a95c347078ec2339303d13024a26910", "0x7c12323a4fff6df1a25d38319d5692982f48ec2e"]}
Batch requests
如果您想知道其他人在用以太坊eth构建什么,您可能需要看看这些项目:
requests = [ {:web3_client_version, []}, {:net_version, []}, {:web3_sha3, ["0x68656c6c6f20776f726c64"]} ] Ethereumex.HttpClient.batch_request(requests) { :ok, [ "Parity//v1.7.2-beta-9f47909-20170918/x86_64-macos/rustc1.19.0", "42", "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad" ] }
Built on Ethereumex
exw3—一个高级合同抽象和其他类似于web3.js的好东西
-
eth—以太坊eth的Elixir实用程序。
-
eth_contract-通过JSON RPC调用eth智能合约的一组助手方法。
-
Ayrat Badykov(@ayrat555)
Contributing
- Fork it!
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Author
以太坊eth是根据麻省理工学院的许可发布的。
License
Ethereumex is released under the MIT License.
部分转自网络,侵权联系删除区块链源码网
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计Ethereumex – 以太坊