MOACTransaction 墨客交易格式
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 Bignumdata.chainId
Number EIP 155 chainId - mainnet: 99, testnet: 101data.gasLimit
Buffer transaction gas limitdata.gasPrice
Buffer transaction gas pricedata.to
Buffer to the to addressdata.nonce
Buffer nonce numberdata.shardingFlag
Buffer shardingFlag, 0 - global transaction, 1 - direct call to MicroChaindata.via
Buffer VNODE via address for MicroChain, can be null for global transactiondata.data
Buffer this will contain the data of the message or the call of a contractdata.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;
}
});