Closed tansaku closed 3 years ago
I've now also tried setting the private key and default account as per the second set of suggestions in https://github.com/EthWorks/ethereum.rb/issues/59#issuecomment-376571671 and that's not working either ... even for a single token:
> client.default_account = account2
> contract.key = Eth::Key.new(priv: your_private_key)
> contract.call.approve(account2, 1) # returns true
> contract.call.increase_allowance(account2, 1) # returns true
> contract.call.transfer_from(account2, account1, 1)
IOError: VM Exception while processing transaction: revert ERC20: transfer amount exceeds allowance
from /Users/samueljoseph/.rvm/gems/ruby-2.7.2/gems/ethereum.rb-2.5/lib/ethereum/client.rb:129:in `send_command'
Also even from a simple transfer which returns true I don't actually see any balance changes:
2.7.2 :021 > contract.call.transfer(account2, 1)
=> true
2.7.2 :022 > contract.call.balance_of(account1)
=> 99998990
2.7.2 :023 > contract.call.balance_of(account2)
=> 10
2.7.2 :024 > contract.call.transfer(account2, 1)
=> true
2.7.2 :025 > contract.call.balance_of(account2)
=> 10
2.7.2 :026 > contract.call.balance_of(account1)
=> 99998990
doh - I should be using transact_and_wait
2.7.2 :042 > client.default_account = "0x624D35BB1f9f2964Ab0A6b37c691141063489ffD"
=> "0x624D35BB1f9f2964Ab0A6b37c691141063489ffD"
2.7.2 :043 > contract = Ethereum::Contract.create(client: client, name: "SohoHouseCoin", address: ENV['SOHO_HOUSE_COIN_CONTRACT_ADDRESS'], abi: abi
2.7.2 :043 > contract.key = Eth::Key.new(priv: '...')
=> #<Eth::Key:0x00007fea3c4e08f8 @private_key=#<MoneyTree::PrivateKey:0x00007fea3c4e0880 @options={:key=>"..."}, @ec_key=#<OpenSSL::PKey::EC:0x00007fea3c4e0858>, @raw_key="...
2.7.2 :044 > transaction = contract.transact_and_wait.increase_allowance(account2, 1)
=> #<Ethereum::Transaction:0x00007fea2b7be018 @mined=true, @connection=#<Ethereum::HttpClient:0x00007fea3ea94298 @id=0, @log=true, @batch=nil, @formatter=#<Ethereum::Formatter:0x00007fea3ea94248>, @gas_price=22000000000, @gas_limit=4000000, @logger=#<Logger:0x00007fea3ea94108...
2.7.2 :045 > transaction = contract.transact_and_wait.transfer_from(account2, account1, 1)
=> #<Ethereum::Transaction:0x00007fea2b0f4fc0 @mined=true, @connection=#<Ethereum::HttpClient:0x00007fea3ea94298 @id=0, @log=true, @batch=nil, @formatter=#<Ethereum::Formatter:0x00007fea3ea94248>, @gas_price=22000000000, @gas_limit=4000000, @logger=#<Logger:0x00007fea3ea94108...
2.7.2 :046 > contract.call.balance_of(account2)
=> 109
2.7.2 :047 > contract.call.balance_of(account1)
=> 99998891
and also works find with:
contract.sender = account2
no need for private key malarcky
so I was reading https://github.com/EthWorks/ethereum.rb/issues/59#issuecomment-369543139 about how to set a non-default sender for a contract operation
Steps to reproduce
Expected behavior
funds should be transfered
Actual behavior
System configuration
Ruby version:2.7.2 Solc version: Parity version: OS: OSX 11.5
Failure Logs
Here's my stack trace:
and the underlying eth log