# ethabi
The ABI, Application Binary Interface, is basically how you call functions in a contract and get data back.
> An ABI determines such details as how functions are called and in which binary format information should be passed from one program component to the next...
An Ethereum smart contract is bytecode, EVM, on the Ethereum blockchain. Among the EVM, there could be several functions in a contract. An ABI is necessary so that you can specify which function in the contract to invoke, as well as get a guarantee that the function will return data in the format you are expecting. [read more](http://ethereum.stackexchange.com/a/1171/394)
This library encodes function calls and decodes their output.
[Documentation](https://docs.rs/ethabi)
### Disclaimer
This library intends to support only valid ABIs generated by recent Solidity versions. Specifically, we don't intend to support ABIs that are invalid due to known Solidity bugs or by external libraries that don't strictly follow the specification.
Please make sure to pre-process your ABI in case it's not supported before using it with `ethabi`.
### Installation
```
cargo install ethabi-cli
```
### Usage
```
Ethereum ABI coder.
Copyright 2016-2017 Parity Technologies (UK) Limited
Usage:
ethabi encode function <abi-path> <function-name-or-signature> [-p <param>]... [-l | --lenient]
ethabi encode params [-v <type> <param>]... [-l | --lenient]
ethabi decode function <abi-path> <function-name-or-signature> <data>
ethabi decode params [-t <type>]... <data>
ethabi decode log <abi-path> <event-name-or-signature> [-l <topic>]... <data>
ethabi -h | --help
Options:
-h, --help Display this message and exit.
-l, --lenient Allow short representation of input params.
Commands:
encode Encode ABI call.
decode Decode ABI call result.
function Load function from json ABI file.
params Specify types of input params inline.
log Decode event log.
```
### Examples
```
ethabi encode params -v bool 1
```
> 0000000000000000000000000000000000000000000000000000000000000001
--
```
ethabi encode params -v bool 1 -v string gavofyork -v bool 0
```
> 00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000096761766f66796f726b0000000000000000000000000000000000000000000000
--
```
ethabi encode params -v bool[] [1,0,false]
```
> 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--
```
ethabi encode params -v '(string,bool,string)' '(test,1,cyborg)'
```
> 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000004746573740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000066379626f72670000000000000000000000000000000000000000000000000000
--
```
ethabi encode function examples/test.json foo -p 1
```
```json
[{
"type":"function",
"inputs": [{
"name":"a",
"type":"bool"
}],
"name":"foo",
"outputs": []
}]
```
> 455575780000000000000000000000000000000000000000000000000000000000000001
--
```
ethabi encode function examples/test.json foo(bool) -p 1
```
```json
[{
"type":"function",
"inputs": [{
"name":"a",
"type":"bool"
}],
"name":"foo",
"outputs": []
}]
```
> 455575780000000000000000000000000000000000000000000000000000000000000001
--
```
ethabi encode function examples/test.json bar(bool) -p 1
```
```json
[{
"type":"function",
"inputs": [{
"name":"a",
"type":"bool"
}],
"name":"foo",
"outputs": []
}]
```
> 6fae94120000000000000000000000000000000000000000000000000000000000000001
--
```
ethabi encode function examples/test.json bar(string):(uint256) -p 1
```
```json
[{
"type":"function",
"inputs": [{
"type":"string"
}],
"name":"foo",
"outputs": [{
"type": "uint256"
}]
}]
```
> d473a8ed000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000013100000000000000000000000000000000000000000000000000000000000000
--
```
ethabi decode params -t bool 0000000000000000000000000000000000000000000000000000000000000001
```
> bool true
--
```
ethabi decode params -t bool -t string -t bool 00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000096761766f66796f726b0000000000000000000000000000000000000000000000
```
> bool true<br/>
> string gavofyork<br/>
> bool false
--
```
ethabi decode params -t bool[] 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```
> bool[] [true,false,false]
--
```
ethabi decode params -t '(string,bool,string)' 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000673706972616c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000067175617361720000000000000000000000000000000000000000000000000000```
```
> (string,bool,string) (spiral,true,quasar)
--
```
ethabi decode function ./examples/foo.json bar 0000000000000000000000000000000000000000000000000000000000000001
```
```json
[{
"constant":false,
"inputs":[{
"name":"hello",
"type":"address"
}],
"name":"bar",
"outputs":[{
"name":"",
"type":"bool"
}],
"type":"function"
}]
```
> bool true
--
```
ethabi decode log ./examples/event.json Event -l 0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000004444444444444444444444444444444444444444
```
> a bool true<br/>
> b address 4444444444444444444444444444444444444444
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
ethabi-master.zip (59个子文件)
ethabi-master
.gitignore 18B
README.md 7KB
CHANGELOG.md 738B
.github
workflows
main.yml 1KB
Cargo.toml 71B
ethabi
Cargo.toml 661B
src
decoder.rs 17KB
errors.rs 1KB
event_param.rs 4KB
token
lenient.rs 2KB
mod.rs 6KB
token.rs 9KB
strict.rs 5KB
signature.rs 1KB
lib.rs 2KB
encoder.rs 29KB
contract.rs 4KB
param_type
param_type.rs 3KB
mod.rs 513B
writer.rs 2KB
reader.rs 8KB
deserialize.rs 2KB
filter.rs 5KB
param.rs 5KB
tests.rs 22KB
event.rs 8KB
util.rs 2KB
tuple_param.rs 3KB
constructor.rs 1KB
log.rs 2KB
function.rs 3KB
operation.rs 4KB
tests
Cargo.toml 277B
src
lib.rs 5KB
LICENSE 9KB
contract
Cargo.toml 451B
src
lib.rs 689B
cli
Cargo.toml 635B
src
main.rs 16KB
tools
solc_compile.sh 170B
publish.sh 379B
res
validators.sol 452B
urlhint.abi 683B
constructor.abi 168B
event.abi 370B
eip20.abi 3KB
foo.abi 338B
test.abi 729B
test_rust_keywords.abi 211B
Operations.abi 7KB
Validators.abi 2KB
.editorconfig 210B
derive
Cargo.toml 607B
src
lib.rs 10KB
contract.rs 2KB
event.rs 10KB
constructor.rs 4KB
function.rs 13KB
rustfmt.toml 79B
共 59 条
- 1
人间发财树
- 粉丝: 27
- 资源: 4560
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- rpi4b基于uboot通过nfs挂载最新主线Linux内核的注意事项
- Cocos2d-x教程视频TMX地图解析
- Cocos2d-x教程视频CocosStudio 2.0 文件格式解析
- 基于 Van.js 的简单前端路由组件(支持字符串和正则表达式匹配等).zip
- Cocos2d-x教程视频CocosStudio 2.0 容器控件
- 学习资源-07~11,备份
- (源码)基于Flink和Kafka的实时用户行为日志分析系统.zip
- (源码)基于Arduino的机器人避障系统.zip
- Cocos2d-x教程视频Cocos2d-x游戏实战项目开发记忆卡片
- (源码)基于FreeRTOS和RP2040的实时操作系统应用模板.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0