Skip to main content

Signing Transactions

By reading this page you will find out how to serialize and sign the Transaction payload.

Transactions must be signed with the Sender's Private Key before submitting them to the MultiversX Network. Signing is performed with the Ed25519 algorithm.

General structure

An unsigned transaction has the following fields:

FieldTypeRequiredDescription
noncenumberYesThe account sequence number
valuestringYes (can be "0")The value to transfer, represented in atomic units:EGLD times denomination
receiverstringYesThe address of the receiver (bech32 format)
senderstringYesThe address of the sender (bech32 format)
gasPricenumberYesThe gas price to be used in the scope of the transaction
gasLimitnumberYesThe maximum number of gas units allocated for the transaction
datastringNoArbitrary information about the transaction, base64-encoded.
chainIDstringYesThe chain identifier.
versionnumberYesThe version of the transaction (e.g. 1).

A signed transaction has the additional signature field:

FieldTypeDescription
signaturestringThe digital signature consisting of 128 hex-characters (thus 64 bytes in a raw representation)

Serialization for signing

Before signing a transaction, one has to serialize it, that is, to obtain its raw binary representation - as a sequence of bytes. This is achieved through the following steps:

  1. order the fields of the transaction with respect to their appearance order in the table above (nonce is first, version is last).
  2. discard the data field if it's empty.
  3. convert the data payload to its base64 representation.
  4. obtain a JSON representation (UTF-8 string) of the transaction, maintaining the order of the fields. This JSON representation must contain no indentation and no separating spaces.
  5. encode the resulted JSON (UTF-8) string as a sequence of bytes.

For example, given the transaction:

nonce = 7
value = "10000000000000000000" # 10 EGLD
receiver = "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r"
sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
gasPrice = 1000000000
gasLimit = 70000
data = "for the book"
chainID = "1"
version = 1

By applying steps 1-3 (step 4 is omitted in this example), one obtains:

{"nonce":7,"value":"10000000000000000000","receiver":"erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r","sender":"erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz","gasPrice":1000000000,"gasLimit":70000,"data":"Zm9yIHRoZSBib29r","chainID":"1","version":1}

If the transaction has an empty no data field:

nonce = 8
value = "10000000000000000000" # 10 ERD
receiver = "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r"
sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
gasPrice = 1000000000
gasLimit = 50000
data = ""
chainID = "1"
version = 1

Then it's serialized form (step 5 is omitted in this example) is as follows:

{"nonce":8,"value":"10000000000000000000","receiver":"erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r","sender":"erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz","gasPrice":1000000000,"gasLimit":50000,"chainID":"1","version":1}

Ed25519 signature

MultiversX uses the Ed25519 algorithm to sign transactions. In order to obtain the signature, one can use generic software libraries such as PyNaCl, tweetnacl-js or components of MultiversX SDK such as mx-sdk-js-wallet, mx-sdk-py-wallet, sdk-go, mxjava, mx-sdk-js-wallet-cli etc.

The raw signature consisting of 64 bytes has to be hex-encoded afterwards and placed in the transaction object.

Ready to broadcast

Once the signature field is set as well, the transaction is ready to be broadcasted. Following the examples above, their ready-to-broadcast form is as follows:

# With data field
nonce = 7
value = "10000000000000000000" # 10 EGLD
receiver = "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r"
sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
gasPrice = 1000000000
gasLimit = 70000
data = "Zm9yIHRoZSBib29r"
chainID = "1"
version = 1
signature = "1702bb7696f992525fb77597956dd74059b5b01e88c813066ad1f6053c6afca97d6eaf7039b2a21cccc7d73b3e5959be4f4c16f862438c7d61a30c91e3d16c01"
# Without data field
nonce = 8
value = "10000000000000000000" # 10 EGLD
receiver = "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r"
sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
gasPrice = 1000000000
gasLimit = 50000
data = ""
chainID = "1"
version = 1
signature = "4a6d8186eae110894e7417af82c9bf9592696c0600faf110972e0e5310d8485efc656b867a2336acec2b4c1e5f76c9cc70ba1803c6a46455ed7f1e2989a90105"