[Ethereum] How to RLP-encode messages in Solidity

casperencodingrlpsolidity

I'm trying to figure out how to interact with the current version of the Casper contract from Solidity. The vote-function in the casper contract takes an array of bytes, which represents the RLP-encoded vote message. Is there a straightforward way of encoding messages using RLP in Solidity?

Best Answer

I don't know if there is any native library available in Solidity, but there are node-js libraries available will help you do that. I also found this solidity code when doing a search on RLP, have a look at the code snippet below:

https://github.com/Giveth/milestonetracker/blob/master/contracts/RLP.sol

Libraries:

https://www.npmjs.com/package/rlp

articles:

http://wanderer.github.io/ethereum/nodejs/code/2014/05/21/using-ethereums-tries-with-node/

https://medium.com/@phansnt/data-structure-in-ethereum-episode-1-recursive-length-prefix-rlp-encoding-decoding-d1016832f919

Here is a thread on RLP Encoding:

RLP decoding question

Hope this helps.