# 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
人间发财树
- 粉丝: 29
- 资源: 4560
最新资源
- 利用五次多项式实现基于模型预测控制的道算法,可根据程序修改自己的算法 matlab2016b,carsim2018
- 西门子大型PLC程序,博途V13 v14 V15 V16 V17版,CPu1511,屏为1200,外加30台G120变频器PN通讯十ET200远程io,温度pid控制,压力处理,张力控制,收卷控
- simulink直流调速系统的仿真模型 晶闸管-直流电动机开环调速系统,基于Matalab2018a
- 电机马达PMSM电机负载观测转矩前馈simulink 基于Luenberger降阶状态观测器,包含PMSM数学模型,PMSM双闭环PI矢量控制,并添加了前馈控制,采用SVPWM调制
- Java毕设项目:基于spring+mybatis+maven+mysql实现的高校食堂订餐系统【含源码+数据库+毕业论文】
- MATLAB驱动防滑转控制ASR牵引力控制TCS模型 ASR模型 驱动防滑转模型 牵引力控制系统模型 选择PID控制算法以及对照控制算法,共两种控制算法,可进行选择 选择冰路面以及雪路面,共两
- 基于FPGA的点阵屏设计,基于Quartus ii开发,Verilog编程语言,也可移植到vivado开发 1、可以显示多个汉字 2、暂停、启动控制 3、左移右移控制 4、调速控制
- omron欧姆龙CJ CP程序 欧姆龙CP1H-XA,主机搭载CIF串口模块与2从机PC LINK通信控制, X,Y轴模组矩阵取放料控制,托盘升降机提升机控制应用 全自动LCD组装机,欧姆龙触摸
- Java毕设项目:基于spring+mybatis+maven+mysql实现的人力资源管理系统【含源码+数据库+毕业论文】
- OMRON大型PLC CJ2M项目案例,配套昆仑通泰触摸屏程序 包含模拟量称重模块,SCU串行通讯模块,通过CMND指令把Fins协议转为MODBUS RTU 控制32台三菱 D720
- 128W微型车载逆变器方案,包含原理图,PCB图,烧录文件,汇编源代码,注意是汇编语言
- MES机台看板系统 可连接24台机,还可以扩展更多 通过网口直接与PLC直接通讯,包含西门子全系列,倍福PLC,三菱,松下,欧姆龙主流PLC 可以读写PLC里面BOOL,int,字符串,汉字(源码
- No.1004 S7-200 PLC和组态王温室大棚温室 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
- Python编程项目:Labyrinth迷宫小游戏完整源码分享给需要的同学
- QT界面开发框架,完整资源与代码一套
- 恒压供水plc程序,三菱FX1N.2N系列plc+fx0n3a模拟量模块+昆仑通态tpc7062触摸屏.全套的图纸十程序,完整的注释,适合参考学习
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0