eth.rb icon indicating copy to clipboard operation
eth.rb copied to clipboard

Is it possible to pass an address array to an eth contract function with transact_and_wait ?

Open LouisRandaxhe opened this issue 1 year ago • 4 comments

Hello, I am trying to transact with an eth contract method that take an address[] memory in arguments.

When I try to pass this array in args of transact_and_wait in my rails app, I have this error : Could not parse address: ["...", "...", ...].

How can I solve that problem ?

LouisRandaxhe avatar Aug 12 '22 14:08 LouisRandaxhe

I have the same problem.

gith-u-b avatar Aug 25 '22 07:08 gith-u-b

Hi,

I would like to be able to do the same.

I am trying to transact with an eth contract method that take an address[] memory in arguments. When I try to pass this array in args of transact_and_wait in my rails app, I have the following error : Could not parse address: ["...", "...", ...].

Thank you for your work.

JDecrypto avatar Sep 23 '22 14:09 JDecrypto

Thanks for raising this. Could you show me an example contract or transaction that causes this issue?

q9f avatar Sep 26 '22 14:09 q9f

Hello,

Here is the Solidity contract function signatures : function distributeNewIncome(uint amount, address[] memory validAddresses) public

And here is how I call it in my Rails app :

@eth = Ethereum.new #instantiate my Ethereum.rb class (see below)

def distribute_income_to_users(contract_address, amount)
    begin
      contract = get_contract(contract_address)
      valid_addresses = Wallet.all.select{|w| w.user.kyc.accepted?}.map{|w| w.eth_address}.to_a #I tried with an array and an array.to_s
      @eth.transact_with_contract(contract,"distributeNewIncome", amount, valid_addresses)
    rescue => e
      raise e
    end
  end

Finally here is the 'transact_with_contract' in my Ethereum.rb file :

@client = Eth::Client.create Parameter.find_by_key("eth_endpoint").value #connection to polygon test network with endpoint saved in db

def transact_with_contract(contract, method, *args) #transaction with contract
    begin
      puts '---Begin transaction---'
      hash = @client.transact_and_wait(contract, method, *args, sender_key: @key, legacy: true, gas_limit: 4000000)
      raise "---Transaction not mined---" unless @client.is_mined_tx?(hash)
      hash
    rescue => e
      raise '---Error---'
    end
  end

LouisRandaxhe avatar Sep 26 '22 14:09 LouisRandaxhe

Do you have any idea when you can solve the problem please?

Thank you very much!

JDecrypto avatar Nov 03 '22 14:11 JDecrypto

I really need to work with your gem and I'm still stuck with this issue.

Will you have time to solve the problem soon?

Thanks a lot!

JDecrypto avatar Dec 06 '22 09:12 JDecrypto

I really need to work with your gem and I'm still stuck with this issue.

Will you have time to solve the problem soon?

Thanks a lot!

JDecrypto avatar Dec 06 '22 09:12 JDecrypto

should be fixed after #194 #191 #185

geth = Client.create "/tmp/geth.ipc"
# => #<Eth::Client::Ipc:0x000055a8e12bccc8 @gas_limit=21000, @id=0, @max_fee_per_gas=0.4269e11, @max_priority_fee_per_gas=0.101e10, @path="/tmp/geth.ipc">
contract = Contract.from_file file: "spec/fixtures/contracts/address_storage.sol"
# => #<Eth::Contract::AddressStorage:0x000055a8e1116b30>
geth.deploy_and_wait contract
# => "0x7aD1FF3AFcA45262C22E32367fAF1B91e24A0909"
geth.call(contract, "retrieveMyAddress")
# => "0x0000000000000000000000000000000000000000"
geth.transact_and_wait(contract, "storeMyAddress", Key.new.address.to_s)
# => "0x5a6728574db598f515e2f93b872d73239efa0470672487325888ce71062835aa"
geth.call(contract, "retrieveMyAddress")
# => "0xbdc4d90b1d46353eb65eca3d0aeb968039f8aa9d"
geth.transact_and_wait(contract, "storeMyArray", [Key.new.address.to_s, Key.new.address.to_s])
# => "0x661ea3fdfdcca66832898917790ea104e54b25753eeb219a5a2b3e7f842005d5"
geth.call(contract, "retrieveMyArray", 0)
# => "0xae2cbef824c78274c6a4910461658e8a390cd9ce"
geth.call(contract, "retrieveMyArray", 1)
# => "0xdd902b8e5d69c08c914c94acc2c1115b6ed74029"

q9f avatar Dec 29 '22 14:12 q9f