Closed toshiboy86 closed 6 years ago
Infura does not hold your key (as if it was if you connected to your own node), and does not know anything about your account. Therefore it is only capable of executing raw (i.e. already signed) transactions.
If you take a closer look on what is actually returned to the HTTP client, you will see, that it's, inf fact "405 Method not supported" response. That's because ethereum.rb tries to send and unsigned transaction via eth_sendTransaction
, and Infura even doesn't have such an API (see docs for reference).
To solve your problem you must persuade ethereum.rb to send raw transactions. This can be achieved if you explicitly assign key
parameter to your @contract
variable.
Assuming that you have a json key file somewhere on your machine, your code will look similar to this:
require 'eth'
TRUFFLE_PATH = '/Truffle/contract/'
#URL = 'HTTP://127.0.0.1:7545' #Ganache
URL = "https://rinkeby.infura.io/v3/xxxx" #Infura
# Reading contents of your key file
json = File.read('/path/to/my/key/file')
# Decrypting key with 'eth' gem
key = Eth::Key.decrypt(json, 'MyP@$$w0rD')
@client = Ethereum::HttpClient.new(INFURA_URL)
@contract = Ethereum::Contract.create(name: "contractName", truffle: { paths: [ TRUFFLE_PATH ] }, client: @client)
# now we have to assign the key
@contract.key = key
@contract.deploy_and_wait("Hello from ethereum.rb!")
Pay attention, that you must explicitly include gem 'eth' to your Gemfile, as it is currently not a dependency for ethereum.rb.
This, unfortunately, cannot be configured in the singleton configuration, and you have to assign the key explicitly each time. It is also closely related to the issue #97 I opened recently.
Thank you Nu-hin. It worked with my Metamask account. There's one issue remained to be solved for me. I have another Ethereum account created with ruby-eth ( https://github.com/se3000/ruby-eth ) in my local machine, but it isn't exposed on public network and doesn't have ether to pay gas cost yet, of course. Is there any ways to expose locally created account on public network ? ( sorry if this question is inappropriate for this place)
Thanks
@Toshiboy86,
Since the Eth network does not validate ownership of addresses before sending funds, there is no need to do anything in order to fund the wallet you created. In other words, once you have your public key, you can use it to receive ethereum. That being said, you will not be able to access the funds without installing the keypair you generated (using ruby-eth) in a wallet such as MetaMask or a node such as Geth.
Here are quick instrustructions for importing keys into metamask wallet:
@Flagship8787
I understood and Issue solved. Thanks.
The execution of the code below causes an error. It works when using Ganache instead of infura. I use wallet created by Metamask.
[code]
[error]
Any hints or tips are appreciated. Thank you.