当前位置: 首页 > 文档资料 > MOAC 中文 WIKI >

MOACTransaction 墨客交易格式

优质
小牛编辑
153浏览
2023-12-01

MOAC transaction format is as the following:

type txdata struct {
    AccountNonce   `json:"nonce"    gencodec:"required"`
    SystemContract `json:"syscnt" gencodec:"required"`
    Price          `json:"gasPrice" gencodec:"required"`
    GasLimit       `json:"gas"      gencodec:"required"`
    Recipient      `json:"to"       rlp:"nil"` // nil means contract creation
    Amount         `json:"value"    gencodec:"required"`
    Payload        `json:"input"    gencodec:"required"`
    ShardingFlag   `json:"shardingFlag" gencodec:"required"`
    Via            `json:"via"       rlp:"nil"`

    // Signature values
    V `json:"v" gencodec:"required"`
    R `json:"r" gencodec:"required"`
    S `json:"s" gencodec:"required"`

}

Send signed transaction to the network is a safe process for the users. The signing process is done through supported MOAC libraries, such as NodeJs, Java, Python.

In nodeJs chain3 library, the signing process can be performed using the signTransaction() in chain3/lib/utils/account.js.

Inputs

  • data Buffer or Array or Object a transaction can be initiailized with either a buffer containing the RLP serialized transaction or an array of buffers relating to each of the tx Properties, listed in order below in the exmple. Or lastly an Object containing the Properties of the transaction like in the Usage example. For Object and Arrays each of the elements can either be a Buffer, a hex-prefixed (0x) String , Number, or an object with a toBuffer method such as Bignum

    • data.chainId Number EIP 155 chainId - mainnet: 99, testnet: 101
    • data.gasLimit Buffer transaction gas limit
    • data.gasPrice Buffer transaction gas price
    • data.to Buffer to the to address
    • data.nonce Buffer nonce number
    • data.shardingFlag Buffer shardingFlag, 0 - global transaction, 1 - direct call to MicroChain
    • data.via Buffer VNODE via address for MicroChain, can be null for global transaction
    • data.data Buffer this will contain the data of the message or the call of a contract
    • data.value Buffer the amount of Moac sent, can be 0 for contract or direct call.
  • key Buffer Private key of the source account

Returns

  • raw Buffer The raw rlp encoded transaction as byte array or a hex-prefixed (0x) String

Example

    var rawTx = {
      nonce: '0x00',
      gasPrice: '0x09184e72a000',
      gasLimit: '0x2710',
      to: '0x0000000000000000000000000000000000000000',
      value: '0x00',
      data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
      chainId: 101,
      shardingFlag: 0
    };

    var signTx = chain3.signTransaction(rawTx, src["key"]);

    chain3.mc.sendRawTransaction(signTx, function(err, hash) {
        if (!err){
            console.log("Succeed!: ", hash);
            return hash;
        }else{
            console.log("Chain3 error:", err.message);
            return err.message;
        }
    });