When I use personal.unlockAccount(), there is an option to pass a parameter for duration. What is the maximum duration to which i can unlock the account? I have searched through its documentation. It only tells me that the duration is in seconds. And if i pass 0 as a duration parameter, the account unlocks permanently. But I want to know what is the maximum duration i can set.

up vote 2 down vote accepted

According to the geth source, there is a max check for the time, which is calculated based of the MaxInt64 value, and ends up as 9223372036 seconds, or roughly 292 years.

// UnlockAccount will unlock the account associated with the given address with
// the given password for duration seconds. If duration is nil it will use a
// default of 300 seconds. It returns an indication if the account was unlocked.
func (s *PrivateAccountAPI) UnlockAccount(addr common.Address, password string, duration *uint64) (bool, error) {
    const max = uint64(time.Duration(math.MaxInt64) / time.Second)
    var d time.Duration
    if duration == nil {
        d = 300 * time.Second
    } else if *duration > max {
        return false, errors.New("unlock duration too large")
    } else {
        d = time.Duration(*duration) * time.Second
    }
    err := fetchKeystore(s.am).TimedUnlock(accounts.Account{Address: addr}, password, d)
    return err == nil, err
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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