[英]Ethereum. Is there a way to know the storage space needed by my smart contract?
How can I quantify how much storage space (approximately) do I need for Ethereum transactions?如何量化以太坊交易需要多少存储空间(大约)? Is it per function/ transaction or how is it calculated?是按功能/交易计算还是如何计算? any leads on this is appreciated.对此的任何线索表示赞赏。 I am trying to quantify the storage space needed for the transactions created by my smart contract...我正在尝试量化我的智能合约创建的交易所需的存储空间......
data
field size如何计算data
字段大小(when you're sending a transaction calling a smart contract function) (当您发送调用智能合约功能的交易时)
The data
field value could be divided into three parts: data
字段值可以分为三部分:
0x
transfer(address,uint256)
=> a9059cbb
示例: transfer(address,uint256)
=> a9059cbb
The easiest way is to use a library that calculates the size for you.最简单的方法是使用为您计算大小的库。 :) For example web3js
function encodeFunctionCall() . :) 例如web3js
function encodeFunctionCall() 。
Example:例子:
const result = web3.eth.abi.encodeFunctionCall({
name: 'transfer',
type: 'function',
inputs: [{
type: 'address',
name: ''
},{
type: 'uint256',
name: ''
}]
}, ['0x1231231231231231231231231231231231231231', '1']);
console.log(result);
Returns退货
0xa9059cbb00000000000000000000000012312312312312312312312312312312312312310000000000000000000000000000000000000000000000000000000000000001
a9059cbb
is the function signature a9059cbb
是 function 签名0000000000000000000000001231231231231231231231231231231231231231
is the address
type (256bit, 64 hex chars) first argument 0000000000000000000000001231231231231231231231231231231231231231
是address
类型(256位,64个十六进制字符)第一个参数0000000000000000000000000000000000000000000000000000000000000001
is the uint256
type (256bit, 64 hex chars) second argument 0000000000000000000000000000000000000000000000000000000000000001
是uint256
类型(256位,64个十六进制字符)第二个参数So the result is 0x
and 136 hex characters, which makes 68 bytes.所以结果是0x
和 136 个十六进制字符,即 68 个字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.