1

I've noticed that some token contracts are requiring me to do an approval before I make a deposit and some do not.

For example. SNT and CVC do not require me to do an approval before I deposit. It may be because, that first time you do an approval it stores that approval somewhere for all future deposits. For BAT and BNT, I must do an approval before every single deposit. Why is that? And how can I programmatically determine this? Can I make an "eth_call" to the contract and get some value that tells me whether or not I need to make an approval before my deposit?

My theory is that the SNT and CVC contracts are approving forever, where as the BAT and BNT contracts are approving that specific amount for that specific deposit. How can I determine this programmatically through the ethereum network? My Parity wallet seems to know, so it must be making some call to the network to learn whether or not it needs to do an approval before a deposit...

Note, i'm making these approvals and deposits to give permission to some other contract.

******************************** Edit ********************************

So I did some reverse engineering and discovered something. If I make this "eth_call" to the token address I get a response. Depending on what that response is tells me whether or not I need to make an Approval AND a Deposit or just a Deposit... I don't really understand it and am having a hard time finding documentation on this topic explaining how this works. But at least I have something to go off of for now. I'm not sure what method corresponds with "0xdd62ed3e".

"id": 1,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
    {
        "data": "0xdd62ed3e000000000000000000000000" + walletAddress_With0xRemoved + "000000000000000000000000" + contractAddress_With0xRemoved,
        "from": walletAddress,
        "to": tokenAddress
    },
    "latest"
]

The response I get may look like this:

u'result': u'0x0000000000000000000000000000000000000000000000000000000000000000'

or like this:

u'result': u'0x00000000000000000000000000000000000000000000000456251106dda27079'

I've discovered that the result being zero means nothing is approved for deposit so it requires approval. And the non-zero result means that amount has already been approved but has not yet been deposited. So you can deposit that much or less. If you want to deposit more than that amount, it seems you have to send an approve with a 0 amount to zero it out, then approve again for a higher amount...

1

It turns out there's no difference in contracts (that I can see). The difference was that two of those tokens already had some amount approved. When I make that call above with the method hash of 0xdd62ed3e, it's returning me how much has been approved already. If that number is not zero, it causes problems...

The reason why I was getting bad jump destinations or bad instructions when trying to deposit was because I was trying to deposit an amount great than what was pre-approved. And the reason why my approval was resulting in a bad jump destination or bad instruction was because it doesn't let me call another approval for an amount greater than what is already approved.

So if 10 tokens are approved, and I try to approve again for 15 (or deposit for 15) it will result in a bad jump destination or bad instruction... The only thing that seems to work is to make an approve call for the amount of 0. It resets the approval value to zero. Then I can make my approve for 15, then deposit 15...

See above edits in OP for additional details.

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.