交易字段
In order to encode a Core Space transaction, the following fields are required:
from
- the address of the sender, that will be signing the transaction. This will be an externally-owned account as contract accounts cannot send transactions.to
- the receiving address (if an externally-owned account, the transaction will transfer value. If a contract account, the transaction will execute the contract code)value
– amount of CFX to transfer from sender to recipient (denominated in Drip, where 1CFX equals 1e+18Drip)nonce
- a sequentially incrementing counter which indicates the transaction number from the accountdata
optional field to include arbitrary datagas
– the maximum amount of gas units that can be consumed by the transaction. The EVM specifies the units of gas required by each computational stepgasPrice
- the price of the consumed gas to be included as a tip to the validatorstorageLimit
- the maximum amount of storage space that can be consumed by the transaction.chainId
- the id of the blockchain, which is used to prevent replay attacksepochHeight
- the epoch number of the blockchain, which is used to sets an expiration time for the transactionsignature
(r,s,v) – the identifier of the sender. This is generated when the sender's private key signs the transaction and confirms the sender has authorized this transaction
基本字段
The from
, to
, and value
are the basic fields of a transaction. These fields correspond to the address of sender account, address of the receiver account and the amount to be transferred, respectively.
from
The from
field identifies the sender of the transaction. Essentially, the from
field tells you who is initiating the transaction and who is paying for the transaction. And in the Signing phase, the transaction will be signed with the private key of the from
account, so you cannot specify arbitary address as the sender.
It is also important to remember that the account must have a sufficient balance to cover both the transfer amount (value
field) and the transaction fee, otherwise the RPC will reject the transaction and it will not be sent.
It's worth mentioning that in some specific cases, Conflux Core Space's sponsor mechanism can allow for other accounts to pay the transaction fee, allowing accounts with 0 balance to send transactions.
In fact, the
from
field is not directly included in an encoded transaction. Generally speaking, tools such as SDKs will remove thefrom
field from transaction before encoding and sign the transaction using corresponding private key. 其他人可以从交易的签名中恢复出发送者。
to
The to
field indicates the recipient account of the transaction.
- If you are making a simple CFX transfer, this field should be set to the CFX recipient's account.
- If you are modifying the state of a contract, the to field should be set to the address of the contract.
- If you are deploying a new contract, the
to
field is left empty.
value
The value
field represents the amount of CFX to be transferred and must be set as an integer in the unit of Drip (10**-18 CFX).
nonce
The nonce
is the execution sequence number of transactions sent from an account. Normally you can get it by calling the cfx_getNextNonce
RPC method.
If you want to expedite transaction processing, you may want to explore the nonce management mechanism further.
data
The data field of the transaction can be left blank or set to a hex-encoded bytes. 这大致可以分为三种情况:
- Regular CFX transfer transaction: The
data
field is usually blank, but hex-encoded data can be set as a transaction remark or postscript. - Contract deployment transaction:
data
needs to be set as the contract's bytecode and the parameters of the constructor (if any) - Contract call transaction: The
data
field is used to store the input data for the contract to call. The data is usually the contract method and data after parameter abi encoding.
智能合约通常用高级合约开发语言(Solidity,vyper)编写。 你可以用编译器获得字节码和 abi。 SDK 会提供 abi 编码方法,用于合约方法调用的编码(编码方法名和参数)。
Fee-Related Fields
There are several fields in the transaction information related to fees, each serving a different purpose.