It depends on your needs.
Usually, while using
ethers.js, Metamask, etc., we create a transaction, sign it and send it automatically. Sometimes you may want to simply create a transaction and sign it without sending it. Maybe you want to wait for something before sending the raw transaction, sharing it, or whatever.
Most of the time you just need to send your transaction and using a tool like
web3.js and passing a JSON with the details of your transaction will be enough.
The EVM does not understand JSON. It only understands hex. So, at the end, your transaction will be converted to hex and sent to the blockchain.
You can sign your transaction using
That will return a response with hex string in the field
rawTransaction, which is the raw transaction hex. You can save it or do whatever you need with it.
You can send/broadcast the raw signed transaction using
web3 sendSignedTransaction function.
You can send a JSON transaction using:
You can copy a raw hex transaction and put it through
web3.eth.accounts.signTransaction to sign it, and then use
web3 sendSignedTransaction to send/broadcast it.
In Metamask you could go to
Settings -> Advance -> Show Hex Data and activate the hex data input to put custom hex data (to call a contract or something like that). I would look like this: