peatio icon indicating copy to clipboard operation
peatio copied to clipboard

ERC20 Withdraw failed

Open go-apollyon opened this issue 8 years ago • 10 comments

Hello there, deposit and withdrawal ETH OK deposit ERC20 OK witdrawal ERC20 - Failed immediate - where i see log in peatio about failed? why failed everytime? the fee withdrawal are been added

go-apollyon avatar Jun 30 '18 17:06 go-apollyon

Wow, what thing in, are you using version 1.8?

vitorgamer58 avatar Jul 03 '18 01:07 vitorgamer58

sure, that we use 1.8

go-apollyon avatar Jul 03 '18 08:07 go-apollyon

I will try to create with this fork a test, if I have problems I put here the results of the LOG.

vitorgamer58 avatar Jul 03 '18 13:07 vitorgamer58

try view on peatio/logs

vitorgamer58 avatar Jul 03 '18 14:07 vitorgamer58

@go-apollyon log files

vitorgamer58 avatar Jul 05 '18 13:07 vitorgamer58

yes but, in the log we don't see why failed.

go-apollyon avatar Jul 05 '18 14:07 go-apollyon

I encountered the same issue. For me, the relevant error message was logged in amqp_withdraw_coin.log:

E, [2018-07-05T12:34:38.604204 #43787] ERROR -- : Error during withdraw processing. D, [2018-07-05T12:34:38.606346 #43787] DEBUG -- : Failed to process gor withdraw with ID 6: #<CoinAPI::Error: {"code"=>-32602, "message"=>"Invalid params: invalid type: integer 5, expected a 0x-prefixed, hex-encoded number of length 32."}>.

I tracked the problem down to this line: https://github.com/rubykube/peatio/blob/61e9aa6c983fe65c5cd9966f8a0623157dbd29e1/lib/coin_api/eth.rb#L163

The 5 argument was not hex-encoded before being sent to my Ethereum node. I'm using Parity as my Ethereum node, and Parity rejects non-hex-encoded arguments, per the Ethereum JSON-RPC spec:

When encoding QUANTITIES (integers, numbers): encode as hex, prefix with "0x", the most compact representation (slight exception: zero should be represented as "0x0").

  • https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding

(I'm guessing this code was tested aganst testrpc/ganache, which sometimes diverges from the spec on number encoding.)

I was able to fix my issue by changing the 5 to '0x5'.

I also had to restart my Parity with the --geth flag, per another error message I got:

#<CoinAPI::Error: {"code"=>-32000, "message"=>"Time-unlocking is only supported in --geth compatibility mode.", "data"=>"Restart your client with --geth flag or use personal_sendTransaction instead."}>

I'm now seeing another error:

E, [2018-07-05T13:05:27.313338 #10883] ERROR -- : Error during withdraw processing. D, [2018-07-05T13:05:27.313567 #10883] DEBUG -- : Failed to process gor withdraw with ID 9: #<CoinAPI::Error: {"code"=>-32010, "message"=>"Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 2400000000000000 and got: 0."}>.

It looks like the "issuer" account that peatio is creating is not given any ETH, so it cannot make transactions. I don't know what solution to propose for that, if that is the problem here. I don't understand how the issuer account is supposed to work.

Hope this is helpful.

jeremyschlatter avatar Jul 05 '18 20:07 jeremyschlatter

but with coin api ETH work good withdrawal and deposit, the problem is ERC20 api. with token i can deposit and i have failed in withdrawal.

go-apollyon avatar Jul 07 '18 19:07 go-apollyon

yes confirm, all ERC20 give failed withdrawal. is a bug of code coinapi erc20

go-apollyon avatar Jul 15 '18 07:07 go-apollyon

Hello. i been debug on this issue withdrawal and i found the solution was to set the valaue to '0x00' as below on file lib/coin_api/erc20.rb

  json_rpc(
    :eth_sendTransaction,
    [{
       from: normalize_address(issuer.fetch(:address)),
       to:   contract_address,
       value: '0x00',
       data: data
    }]

The reason why it fail earlier as eth_sendTransaction was generic parameter. For token, we need to send the value to '0x00'

myujang avatar Jul 26 '18 16:07 myujang