nebulasio / web-wallet

GNU Lesser General Public License v3.0
265 stars 188 forks source link

Unable to send NAS. #25

Closed bachvtuan closed 6 years ago

bachvtuan commented 6 years ago

I claimed some NAS here but when I send NAS to another address it alert Error: invalid address . I tried to send offline and I get another message is RangeError: private key length is invalid

ottokafka commented 6 years ago

Hello Bechvtuan, I need to see what code your using to further understand the problem.

bachvtuan commented 6 years ago

I downloaded your latest code in this morning.

ottokafka commented 6 years ago

above you stated that you are trying to send a transaction. What code are you using to send the transaction?

bachvtuan commented 6 years ago

I used your client web. Here is a screnshot

ottokafka commented 6 years ago

I found the problem. This is a problem with the backend Which requires a json account address which carries the public address, private address and account address. So when you enter a string address the backend give you that error. You can check out my version of Nebulas playground to understand how thing work. https://ottokafka.github.io/nebulasPlayground/

bachvtuan commented 6 years ago

I see. Do you have any idea to make current code work ?

ottokafka commented 6 years ago

Yes I do I can explain the problem. image Behind the scenes the Account.NewAccount() account.getAddressString() account.getPublicString() account.getPrivateString() above is being called to create a address.

Than image new Transaction(testnetchainID, account, toAddress, value, nonce = nonce + 1, gasPrice, gasLimit); tx.signTransaction(); Behind the scenes there is a signing of the address which accepts strings

Finally - image

We Submit the transaction. neb.api.sendRawTransaction(tx.toProtoString()); txhash = resp.txhash; The problem is: new Transaction(account, toAddress, value, nonce = nonce + 1, gasPrice, gasLimit); The account here actually needs to be a object not a string. You can see how accounts are a created from my example above.

bachvtuan commented 6 years ago

Thank you. btw, I tried your playground and see transaction was broadcast from there are pending https://explorer.nebulas.io/#/address/df7c777a4a10e60a4a36db7852dcb3837ae690f20fe00293

ottokafka commented 6 years ago

Hey Tuan,

I just updated the code will update now.

ottokafka commented 6 years ago

Thank you for letting us know about this bug. We appreciate your feedback.

bachvtuan commented 6 years ago

Great It worked. However I found another weird issue that I have 10 NAS but I think the gas fee can it take a bit so I send 9.99 NAS I see the generated code here look correct

{"chainID":1001,"from":"f3d5620a2768b1ca21ccec2ddd475269f48d54fde6efdbb4","to":"df7c777a4a10e60a4a36db7852dcb3837ae690f20fe00293","value":"9990000000000000000","nonce":1,"timestamp":1521707205,"data":{"payload":null},"gasPrice":"1000000","gasLimit":"20000","hash":"6fb8c9f7a003a144f3fe8f01a68ce89cbf8da7fcf44dc419fa0274b0950dfe18","alg":1,"sign":"464eba3aacdbb91d7d972b32157a69617de7ef0d4ffecc20ce9d105ac9d3c11d16666b52d3ddad7187cff1a30c1bdb2ab90493c6eaea31dfcd1d951bc737189700"} value is = 9990000000000000000 ( 9990000000000000000 / 1E18 = 9.99)

But I see on explore nas value is 10 and it's still pending at transaction

fbzhong commented 6 years ago

Hi @bachvtuan

I checked your tx, it look like the from address has no NAS token to transfer.

The from address f3d5620a2768b1ca21ccec2ddd475269f48d54fde6efdbb4 has 0 NAS, the transaction will be rejected. The to address df7c777a4a10e60a4a36db7852dcb3837ae690f20fe00293 do have 10 NAS.

You can check the balance and Nonce from https://testnet.nebulas.io/claim/ page.

bachvtuan commented 6 years ago

@fbzhong My source address is 5221545f201d317b6272afd0c307f2dc65e9f23743d6b6c1 and it does have 10 NAS. I think I detect weird thing here that I generate transaction and transaction raw transaction give me different address with source address ( it should be 5221545f201d317b6272afd0c307f2dc65e9f23743d6b6c1 ? )

screenshot from 2018-03-22 15-42-07

{"chainID":1001,"from":"5b49adeaa6c53857e2cae231ebf41476841384ac6f5c18c3","to":"df7c777a4a10e60a4a36db7852dcb3837ae690f20fe00293","value":"-20000000000","nonce":0,"timestamp":1521708126,"data":{"payload":null},"gasPrice":"1000000","gasLimit":"20000","hash":"f3af55cd23646771d81ec92d7f722f66d505c146cb5fd405d7c1f13e73973a1b","alg":1,"sign":"c711672f8b0ecdc2cd418af326f0ab087407c874802fcddd396bc75573c13b5d4abdbd3d750e11d09f4fde80e8e56a321910ee47c59f5d8c8374ef1c81ac79e401"}

where is address 5b49adeaa6c53857e2cae231ebf41476841384ac6f5c18c3 ?

fbzhong commented 6 years ago

Hi @bachvtuan

There is a bug in sendNas.html file, the function onClickGenerate() will generate a new account and signed the tx, not using the account you just provided.

@wangzimei please record and fix it.

wangzimei commented 6 years ago

fixed by use account object aquired by select file https://github.com/nebulasio/web-wallet/commit/deaf8d19b7c1bbb7c68581514661bebb34d6846b