q9f / eth.rb

a straightforward library to build, sign, and broadcast ethereum transactions anywhere you can run ruby.
https://q9f.github.io/eth.rb
Apache License 2.0
200 stars 86 forks source link

eth/contract hello_world "already known" bug? #118

Closed unixneo closed 2 years ago

unixneo commented 2 years ago

Hi. Thank you for this gem. I have been debugging for hours adding print statements and trying to get past an issue with gem where every time I submit a simple hello world, or hi there contract, I get the same error:

{"jsonrpc"=>"2.0",
 "id"=>7,
 "error"=>{"code"=>-32000, "message"=>"already known"}}

This issue has been ongoing for a week now, so please forgive my annoying posts. I am simply trying to use the eth gem to deploy the most simple Hello World contract I can, and it will not work regardless of what I change, read, study or try.

I read that the way around this "already known" error was to cancel the transaction by sending zero ETH (test ETH) to and from the same address, which I did with MetaMask for a number of addresses, and all these "send zero to myself transactions" worked without flaw using MM.

However, then I try to deploy "Hello World" or "Hi There" again using the same address where I just send myself 0 ETH, on the same chain of course, I still get:

{"jsonrpc"=>"2.0",
 "id"=>7,
 "error"=>{"code"=>-32000, "message"=>"already known"}}

FWIW, one of the blockchain providers I use told me that they could deploy using curl and so they did not understand this issue; which seems to be related to eth.rb but despite adding countless print statements, reading the docs, and debugging the best I can consider I am not an expert with eth.rb nor the EVM.

If someone can post some simple ruby code using this gem to deploy "Hello World", that would be very helpful at this point in time. I can try that code and see if it works. I searched the net and read the eth docs many times, and I cannot find a working "Hello World" contract deployment example using this gem; but of course, I could have missed it after a week of hand banging :)

My apologies if posting these issues are annoying or if I am posting incorrectly. If I had the required experience with the EVM and this gem, I would gladly push some changes, believe me :)

Thank you.

Hello World

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract HelloWorld {
   function helloWorld() external pure returns (string memory) {
   return "Hello, World!";
   }
}

Note: I recall when I wrote my first client-server socket program over 30 years ago, even with no experience in C programming, I could send "Hello World" across the network using client and server sockets in just a few hours, just opening books on C programming. It seems to me that "Hello World" on the EVM using this Ruby gem should not take weeks, to be honest, but what do I know ;)

unixneo commented 2 years ago

Fixed nonce issue in debug code.