Turbo Streams
Jul 22, 22 by Juan Lebrijo about blog

Actions and Targets

An example on how turbo_stream is rendered:

= turbo_stream.append :messages, @message
Where :messsages is the target and @message renders the partial _message.html.haml. Then it is rendered to:
  
    
// This div will be append to element with id="messages"
7 possible Actions
  • APPEND: Appends template to target
  • PREPEND: Preppends template to target
  • REPLACE: Replaces the full target with template
  • UPDATE: Replaces the content of target with template
  • REMOVE: Removes target
  • BEFORE: Adding template before target element
  • AFTER: Adding template after target

Streaming from HTTP responses

In rails controller streams will be rendered like:
def create
  @message = Message.find(....)
  
  respond_to do |format|
    format.turbo_stream # renders template in: create.turbo_stream.haml
    format.html { redirect_to messages_url }
  end
end
Reusing server side templates inline:
  format.turbo_stream do
    render turbo_stream: turbo_stream.append(:messages, 
                partial: "messages/message", locals: { message: @message})
  end
Both "partial:" and "locals:" can be replaced by @message (Great Rails code!!!).

Some notes

RECOMENDATION: Good practice is design without Streams, then in poor connections or server issues, when web sockets are broken, it will run anyway. Like a browser without JavaScript. NOTE FOR BROWSER CACHE: Attribute "data-turbo-permanent" makes element alwaiys the samen in browser cache.
Ethereum addresses in Solidity
Jul 21, 22 by Juan Lebrijo about Solidity, Ethereum, blog
ETH addresses are hexadecimal like: 0x123AFD... The same addresses can be owned by a wallet or by Smart contract deployment. So you can send and get balance of both. Basic functions are:
  • address.balance: total weis in account (1 ETH == 10^18 weis).
  • address.transfer(amount): send an amount in weis, raising an exception if error.
  • address.send(amount): returns true if success instead of raising an exception.
Transfer/send costs are 2300 in gas. Global objects in a contract are:
  • msg.sender: Sending address
  • msg.value: weis sent
  • now: current timestamp
Functions or addresses should be marked as PAYABLE to receive ETH.
Quick basic introduction to Ethereum Development
Jul 20, 22 by Juan Lebrijo about blockchain, Ethereum, blog

You need to install Metamask as an extension in your Chrome browser. After that, create a wallet address and change to Ropsten Test Network.

1_k5aYGAd7CvRHO-o230nCPw-12.gif 397 KB

Now go to buy ETH and get it from a Test faucet. Then you can play with it by creating another account and sending ETH between them.

Here the big thing is the TRANSACTION SIGNATURE, how knows the Network that you are really the owner of this transaction? Because of Asymmetric signature, you will sign the transaction with your Private Key, so the node knows you are, because it decrypt with your Public Key. Metamask do all of it for you, also saves your private key.

Now you have ETH to test your wallet, you will code with SOLIDITY.

  • It is a language based on JavaScript designed to target Ethereum Virtual Machine (EVM).
  • Statically typed, supports inheritance, libraries and complex user-defined types. And compiled in Bytecode.
  • You can create SMART CONTRACTS with it.
  • You can find whole guide to this language at https://docs.soliditylang.org/
  • You can use Remix as web editor in your browser, or Truffle installed locally.
  • In order to test your contracts you have several options:
    • Injected Web3: testing over Ropsten Network directly.
    • JavascriptVM: more agile, but it is a Network simulation.
    • Web3 Provider: which mounts an ETH Blockchain in your Laptop, from Genesis Block. Ganache, which belongs to TruffleSuite, can do it really clean.

Enjoy your learning!!