At this time I'm just trying to setup the simplest of apps where I click a button and that will send the most basic of transactions to my testrpc network. It's easy to do with JS and web3, but how can I do this with Ruby on Rails ?
2 Answers
There are many ways to connect Rails with Ethereum,
I recently used
- coinfalcon for Python and Ruby. This provides API for placing orders with the help of this.
- Ethereum Ruby This helps you connect with Ethereum.
Here you can do:
- IPC Client Connection
- Solidity contract compilation and deployment
- Transacting and Calling Solidity Functions
I have published an Ethereum on Rails template.
It is a boilerplate application that allows authenticating users in your Rails 7.0 application with an Ethereum wallet (e.g., MetaMask).
You can use this repository as a template to create your custom Rails application that already has Ethereum support bundled. For example, it uses the new eth
gem for Ethereum account management.
If you already know how to use Rails, you can utilize the following functionality of the eth
gem:
test_rpc = Eth::Client.create "http://127.0.0.1:8545"
some_trx = Eth::Tx.new {
chain_id: test_rpc.chain_id,
nonce: test_rpc.get_nonce test_rpc.default_account,
priority_fee: 1 * Eth::Unit::GWEI,
max_gas_fee: 23 * Eth::Unit::GWEI,
gas_limit: Eth::Tx.estimate_intrinsic_gas,
to: Eth::Address.new "0xCaA29806044A08E533963b2e573C1230A2cd9a2d",
value: 1 * Eth::Unit::ETHER,
}
And then you can sign and broadcast it, see: https://github.com/q9f/eth.rb/wiki/Transactions
Or simply run:
test_rpc.transfer Eth::Address.new("0xCaA29806044A08E533963b2e573C1230A2cd9a2d"), 1 * Eth::Unit::ETHER