How to Transfer 0xBTC with no ETH
If you are like me, you are fascinated by the idea that there is a pure mined currency running on top of (inside of?) Ethereum with over 10TH/s of SHA3 Proof of Work hashpower. However, the fact that you also need ETH to pay for gas is annoying. Why not just pay for gas using 0xBTC? It is a digital currency after all.
At the moment, the Ethereum miners processing Ethereum Transactions do not accept ERC20 tokens as incentive to include a new tx. That is a story for another time. So what if we just set up middleman relay servers that submitted our TX for us using ETH, and accepted ERC20 tokens as payment for their work?
In order to do this trustlessly, we just need to be able to verify offchain signatures in Solidity. Fortunately, with ECRecover and EIP712, this is very easy to do! Metamask even supports Signed Typed Data for added user friendliness.
The Lava Protocol is a new standard for signing typed data that describes an ERC20 token transaction with a fee paid in tokens. This is very similar to a ‘signed check’ in real life and is also called a ‘lava packet’. The difference is, it is cryptographically secure and anyone can submit it to the Ethereum Network for a reward paid in ERC20 tokens!
The Solidity contract that makes this possible is called the Lava Token contract. In this case, it is a 1:1 Proxy Token for 0xBTC with an extra method called transferTokensWithSignature that accepts the following input parameters of a Signed Lava Packet:
Using ECRecover, the contract verifies that the token owner (from) really did produce the signature for the hash of all of this data. If so, the contract conducts the transaction! Here is how that looks in practice at http://relay.0xbtc.io :
- Atomic swap 0xBTC to LAVA Proxy Token, 1:1 (you can always swap back)
https://etherscan.io/tx/0xacff03194343462e8b6a11b7a9dd4de485ca73a09d39c9fb20b051da81ab8e90
2. Generate an offchain signature for a new LAVA transaction using software that supports EIP712 like Metamask
3) Provide this Lava Packet (9 input parameters + signature) to any Lava Relay Node (https://github.com/admazzola/lava-relay-node) and it will process the transaction, paying the ETH fee and claiming the ‘Relay Reward’ (tokens) as payment.
As soon as a Lava Relayer gets their hands on that data, they will inspect the Fee to see if it is high enough. If so, they will submit the transaction to the Ethereum Mainnet like this:
4) Once the transaction goes through, the recipient will have received the ERC20 tokens even though you spent no ETH for the tx! This was all done trustlessly and with the same elliptic-curve signature algorithms used for Ethereum TX themselves, just processed in solidity. If you want, you and the recipient can convert the LAVA Proxy tokens back to 0xBTC with an on-chain method.
Protip: By taking advantage of the ApproveAndCallWithSignature feature, you can actually convert your LAVA back to 0xBTC with no ETH by using a middleman ‘Fire Contract’, a contract like this: https://etherscan.io/address/0x16118cfdbf415e06291e79b72e3b793647fe2dd6#code
(Inspired by BokkyPooBah’s Token Teleportation Service — https://github.com/bokkypoobah/BokkyPooBahsTokenTeleportationServiceSmartContract)