1

I have some idea of what "locking ether" means, but I need to understand for sure. AFAIK, tokens exist at some address, but according to many sources, the token is locked in a smart contract for some period of time. What is the reality? Do tokens get locked at the source address for the time-limit, or at some temporary neutral storage location (address) before it is sent to the destination? I am wondering in the case where someone wants to prevent themselves from using some amount of tokens using this locking mechanism. In that case, there is no destination. How does the code work? The source and destination are the same, or do the funds get locked in a neutral storage location to be returned to the initial address after the vesting period is over.

1

1 Answer 1

1

It's not entirely clear what you're asking, but I'll address some of the points you made.

AFAIK, tokens exist at some address, but according to many sources, the token is locked in a smart contract for some period of time.

Just to be clear: ERC-20 tokens only ever exist in the token contract as a balance associated with an address. They never exist anywhere else. When a transfer occurs between two addresses, all that is happening is that two balance variables in the token contract are changed.

Do tokens get locked at the source address for the time-limit, or at some temporary neutral storage location (address) before it is sent to the destination?

I think you're asking about something like Open Zeppelin's TokenTimeLock utility. This isn't part of the standard specification, but is a separate contract that interfaces with an ERC-20 contract to allow time locks to be used.

The source and destination are the same, or do the funds get locked in a neutral storage location to be returned to the initial address after the vesting period is over.

As per my first point, ERC-20 tokens never leave the token contract - they only exist as a balance inside the contract itself. All the time lock does is prevent these balances from being changed (for a particular address or set of addresses) for the desired length of time.


Edit:

Just looking at the TokenTimeLock code, it works by checking whether the unlock block number has been reached:

require(releaseTime_ > block.timestamp, "TokenTimelock: release time is before current time");

I'm sure other locking mechanism exist elsewhere, but this seems the most pertinent given you've used the tag.

10
  • Great answer!!!!!!!!!!!!!!!!!!!!!
    – blue_ego
    Commented Mar 5, 2021 at 16:15
  • does the contract code poll the chain for the latest block's timestamp?
    – blue_ego
    Commented Mar 5, 2021 at 16:39
  • Also, it doesn't make sense exactly what you say, " two balance variables in the token contract are changed"...how does this really happen? contracts are just code right?
    – blue_ego
    Commented Mar 5, 2021 at 17:10
  • For your first question: When a user wants to transfer an amount of tokens, they submit a transaction. When that transaction is mined and put into a block to be included in the blockchain, certain details of that block become available to, and can be used by, the transaction. The block number is one of the values that is available. Commented Mar 5, 2021 at 17:41
  • Second question: There's actually only one variable that gets changed - the _balances mapping. Inside the mapping each address is mapped to its balance. The source address has its balanced reduced by the amount that is added to the destination address. Commented Mar 5, 2021 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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