For the past few days I have been testing the eth
gem and various blockchain provider endpoints. Here are the endpoints I have been testing, which are in a module I created located in my test file, not surprisingly called endpoints.rb
:
module Endpoint
class Provider
def initialize
end
def self.get(provider_network=ENV['ALCHEMY_ENDPOINT_GOERLI'])
if provider_network == "alchemy_mainnet"
ENV['ALCHEMY_ENDPOINT_ETH_MAINNET'].nil? ? nil : ENV['ALCHEMY_ENDPOINT_ETH_MAINNET']
elsif provider_network == "getblock_goerli"
ENV['GETBLOCK_ENDPOINT_GOERLI'].nil? ? nil : ENV['GETBLOCK_ENDPOINT_GOERLI']
elsif provider_network == "quicknode_ropsten"
ENV['QUICKNODE_ENDPOINT_ROPSTEN'].nil? ? nil : ENV['QUICKNODE_ENDPOINT_ROPSTEN']
elsif provider_network == "quicknode_goerli"
ENV['QUICKNODE_ENDPOINT_GOERLI'].nil? ? nil : ENV['QUICKNODE_ENDPOINT_GOERLI']
elsif provider_network == "chainstack_ropsten"
ENV['CHAINSTACK_ENDPOINT_ROPSTEN'].nil? ? nil : ENV['CHAINSTACK_ENDPOINT_ROPSTEN']
elsif provider_network == "chainstack_goerli"
ENV['CHAINSTACK_ENDPOINT_GOERLI'].nil? ? nil : ENV['CHAINSTACK_ENDPOINT_GOERLI']
elsif provider_network == "alchemy_goerli"
ENV['ALCHEMY_ENDPOINT_GOERLI'].nil? ? nil : ENV['ALCHEMY_ENDPOINT_GOERLI']
elsif provider_network == "alchemy_rinkeby"
ENV['ALCHEMY_ENDPOINT_RINK'].nil? ? nil : ENV['ALCHEMY_ENDPOINT_RINK']
else
ENV['ALCHEMY_ENDPOINT_GOERLI'].nil? ? nil : ENV['ALCHEMY_ENDPOINT_GOERLI']
end
end
end
end
As you can see from the module, I "over coded" this nil
check
Basically, with this module we can easily update the endpoint provider list as needed and use the endpoint provider and the name of the Ethereum test chain, like so; which you can see takes the name of the contract and the "provider_network" combination which represents the blockchain service provider and the name of the test network (as simple Strings):
chain = Eth::Client.create Endpoint::Provider.get(provider_network)
Using this simple idea, I created a basic method using the eth
gem to test the most basic hello_world.sol
smart contract:
module EthGem
require "eth"
require_relative "#{Rails.root}/lib/assets/config.rb"
class Core
include Endpoint
include Wallet
def initialize
end
def self.contract(file="hello_world",provider_network=="alchemy_goerli")
return nil if file.nil?
chain = Eth::Client.create Endpoint::Provider.get(provider_network)
deposit_contract = Eth::Address.new Wallet::Address.metamask_eth
balance = (chain.get_balance deposit_contract).to_f
puts "Balance is #{balance.round(8)}"
puts "FILE: #{contract_file}"
contract_file = "#{Rails.root}/lib/assets/contracts/#{file}.sol"
contract = Eth::Contract.from_file(file: contract_file)
chain.deploy_and_wait(contract)
end
end
end
Amazingly, none of these blockchain provider tests worked as expected for a number of reasons and it's interesting and instructive to look at each provider and their error message returned, which I will launch in the Rails console, as in the following example:
MacStudio:eth tim$ rails c
Loading development environment (Rails 7.0.3)
irb(main):001:0> require "#{Rails.root}/lib/assets/eth.rb"
=> true
irb(main):002:0> EthGem::Core.contract("hello_world","alchemy_goerli")
In each case, we also print the balance of our test ETH in each test network just to show the API is "working" in it's most simple method, getting a balance of ETH in the network.
alchemy_goerli
irb(main):002:0> EthGem::Core.contract("hello_world","alchemy_goerli")
Balance is 1.1e+18
FILE: /Users/tim/rails/eth/lib/assets/contracts/hello_world.sol
/Users/tim/rails/eth/vendor/bundle/ruby/3.0.0/gems/eth-0.5.5/lib/eth/client.rb:453:in `send_command': Unsupported method: eth_coinbase. Alchemy does not support mining eth. See available methods at https://docs.alchemy.com/alchemy/documentation/apis (IOError)
Note that for Alchemy, they provide a very instructive error message. This error occurs regardless of which test network we try on the Alchemy-hosted blockchains.
I reported this issue to the owner of the eth
gem and received a light thank you
and he tagged this as an eth
gem bug here:
So, although I cannot yet deploy Hello World contract on an Alchemy Ethereum test network using the eth
gem, we learned that Alchemy returns informative error messages and that the eth
gem owner is actively supporting the eth
gem. This is all good news.
chainstack_ropsten
irb(main):003:0> **EthGem**::**Core**.contract(**"**hello_world**"**,**"**chainstack_ropsten**"**)
Balance is 1.0400990549999952e+20
FILE: /Users/tim/rails/eth/lib/assets/contracts/hello_world.sol
/Users/tim/rails/eth/vendor/bundle/ruby/3.0.0/gems/eth-0.5.5/lib/eth/client.rb:453:in `send_command': **etherbase must be explicitly specified (****IOError****)**
This "etherbase" error is vague, but so far I have not reported the issue to the eth
gem repo, as I do not wish to overwhelm the developer with my test results. However, early in my testing, I reported this error to Chainstack, who came back with me with a proposal for $1,600 USD per day to help me fix this issue
I will note at this point that Alchemy lets us freely create and test up to five different blockchain endpoints, where Chainstack only permits one. Testing multiple chains on Chainstack requires deleting endpoints, which is annoying. When I first deleted an endpoint to create another one for a different test network, I received some sales-related email from Chainstack asking me to upgrade to the paid tier.
getblock_goerli
irb(main):004:0> EthGem::Core.contract("hello_world","getblock_goerli")
/Users/tim/.rbenv/versions/3.0.3/lib/ruby/3.0.0/json/common.rb:216:in `parse': 809: unexpected token at 'Apikey missed' (JSON::ParserError)
As you can see, this API endpoint just dies. When I double checked the GetBlock docs, there is no clue about this error. I suspect it might be an error in the eth
JSON parser; however, I have not yet reported this issue to the eth
gem repo owner. I have not yet interacted with GetBlock support and do not have any current plans to do so.
quicknode_goerli
irb(main):007:0> EthGem::Core.contract("hello_world","quicknode_goerli")
/Users/tim/.rbenv/versions/3.0.3/lib/ruby/3.0.0/json/common.rb:216:in `parse': 809: unexpected token at 'Not Found' (JSON::ParserError)
Quicknode tests did not get very far and we got a similar JSON parsing error in the eth
gem as with GetBlock.
The problem as a developer testing Quicknode endpoints is that they charge $9 per node per month to test. Alchemy, on the other hand, provides 5 free nodes to developers. Alchemy has been very easy and smooth to work with so far.
Regarding the parsing errors, I suspect the issue may be related to the JSON parsing method in the gem, but have not reported this issue to the owner yet.
Maybe I will report these issues to the eth
gem repo later this week.
Regarding Quicknode support, I have been chatting with one of there team member in India who has been helpful and friendly. He also provided me with 4 free Ropsten test network ETH before I found some faucets and now I have nearly 400 Ropsten ETH (rETH). A link to a list of faucets to get free test ETH is at the bottom.
Summary
I have tested Ethereum endpoints deploying the most basic Hello World contract for four blockchain hosting providers (1) Alchemy, (2) Chainstack, (3) GetBlock and (4) Quicknode.
When we search the net for reviews on each of these providers, we find a lot of top 10 lists and other click-bait which is 99% copy-and-paste SEO text without any real testing or understanding of what or how to test.
However, in this case, I have signed-up for, and tested, four providers and found Alchemy to be the best from (1) a "free developer tier" perspective, (2) an error message return perspective and (3) a dashboard perspective (which I did not show here).
The bottom line is that I cannot yet deploy a Hello World "smart" contract on an Ethereum test network. It appears that there are still some bugs to work out with the eth
gem as far as parsing JSON data and interacting with different provider blockchain endpoints.
I have reported one of the issues to the eth
gem owner, who has gently acknowledged this bug. I have not yet reported the JSON parsing error, as I am trying to be gentle and not inundate a fellow developer, who is a busy coder and doing an "act of kindness" making this gem available for everyone, with issues.
Hopefully, I can find a provider endpoint (free) where I can get a Hello World contract to deploy on an Ethereum test network; but I think the issue fall in the scope of the eth
gem and not with the endpoint blockchain provider.
Hope this helps!
List of Faucets for Free Test ETH
Some of the links in this GitHub list are dead, others are great. This is a good place to start if you are searching for test ETH.
Update: Reported These Issues
Assuming the developer would like to know....
Final Thoughts
Would be great if people who post tutorials and "top 10 lists" on the net would actually use and test the services they are posting click-bait about; but I that "wish" is not going to happen as the trend is more click-bait SEO "reviews" and "tutorials", less "signal" and a lot more "noise".
However, with my tests, you are getting real tests and zero click-bait.