4

I wanted to highlight a problem we all suffer from when using third party API's. Let's say you want to make an ethereum transaction. Normally the API will return a txid when the request is successful. But in my example the request has an unknown error. No txid is returned from the API.

When an API call fails for any reason the standard assumption is that the transaction wasn't successful. In my experience with almost every API this assumption is completely wrong. The transaction could still be successful even though the API returns an error. I've seen this multiple times with bitcoind and exchange API's.

So when we receive an error creating a transaction we want to figure out if the transaction was successful or not. Otherwise you might end up sending the transaction multiple times. The problem here is that we don't have a txid to do a simple transaction lookup.

Ideally I want to give my own reference ID with every transaction. This way I don't have to rely on the txid that is given to me by the API. Sadly this isn't a parameter in the current json-rpc API.

I solved this problem in bitcoind by using the "comment" field for my own reference ID. I than iterate through the last X amount of transaction and I try to find a match with the transaction comment and reference ID.

Any suggestions on how to solve this problem with Ethereum?

  • If I understand correctly, you could put your reference ID in the data field of a transaction ethereum.stackexchange.com/q/2466/42 and look for your ID when you iterate through the last X transactions? – eth Apr 5 '16 at 19:36
  • As you can see im a complete ethereum noob. I didn't know the data field could hold a message. The documentation is told me it's meant for contract code. Thanks for the quick awnser – Ivan da Silveira Apr 5 '16 at 20:14
  • You're also correct: when to field is empty, you put the contract code in the data field. Also, I posted an answer instead of marking your question as duplicate, because there may be other solutions to the general problem. – eth Apr 5 '16 at 21:48
3

Ideally I want to give my own reference ID with every transaction.

Data can be attached to any transaction using the data field.

Here is an example in web3.js:

eth.sendTransaction({data:web3.toHex('123456'), from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(1‌​00,'finney')})

The data should be in hex. A string is passed to toHex so that the ID is treated as a BigNumber (since Javascript does not have native big numbers).

When you are reading the hex data, convert it back to a string ID using new BigNumber(hexData).toString().

The more data attached to a transaction, the more gas it will cost, so keep that in mind with the IDs you use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.