I worked the Token tutorial. At one stage, newly minted tokens can be supplied to a target address. However, when I provide the address from a test account on a private net (eth.account[1]), I get an error:

> eth.accounts
["0xf134f55797c344c5894d009d2784c0f32fd74199", "0x922d2931678e0641dc7d13cb38a2f0897252b0de"]
> token2.mintToken(eth.accounts[1], 1000000)
invalid address
    at web3.js:3887:15
    at web3.js:3713:20
    at web3.js:4939:28
    at web3.js:4938:12
    at web3.js:4964:18
    at web3.js:4989:23
    at web3.js:4055:16
    at web3.js:4141:16
    at <anonymous>:1:1

I got the same error, when truncating the address by the prefix 0x, as I read about somewhere else.

How else do I need to format an address to provide to a contract?

Address is valid:

> var isStrictAddress = function (address) {
....     return /^0x[0-9a-f]{40}$/i.test(address);
.... };
> isStrictAddress
> isStrictAddress(eth.accounts[0])

2 Answers 2


If you're trying to pass a literal address (like in the mintToken function), it must be in a string and prefixed with 0x. For instance:


Alternatively, you can pass an address from the eth.accounts array. (Note the plural variable name - "accounts" not "account".) For instance:


It looks like this is the web3.js code that's throwing:

var inputAddressFormatter = function (address) {
    var iban = new Iban(address);
    if (iban.isValid() && iban.isDirect()) {
        return '0x' + iban.address();
    } else if (utils.isStrictAddress(address)) {
        return address;
    } else if (utils.isAddress(address)) {
        return '0x' + address;
    throw new Error('invalid address');


var isStrictAddress = function (address) {
    return /^0x[0-9a-f]{40}$/i.test(address);

(isStrictAddress() should pass with the address you've given above.)

  • 1
    In my case, eth.accounts[0] returns a string and is identical to a string prefixed by 0x. Submitting a string returns invalid address. But I'm submitting by eth.accounts[0], which exists?!
    – TMOTTM
    Commented Jun 27, 2016 at 20:15
  • Can you update your question with a transcript of your console session?
    – Jamie Hale
    Commented Jun 27, 2016 at 20:38
  • I added console output.
    – TMOTTM
    Commented Jun 27, 2016 at 21:24
  • Interesting. Any chance you can add the contract code? The address looks valid, and seems to pass a visual check. I wonder if you have the parameters reversed? Like maybe the 1000000 is being passed to an address parameter, and confusing things?
    – Jamie Hale
    Commented Jun 27, 2016 at 21:51
  • 1
    Ok, and if I would like to keep working with the source?
    – TMOTTM
    Commented Jun 30, 2016 at 4:51

Try to set the default account and then execute:

web3.eth.defaultAccount = web3.eth.accounts[0]

Hope this helps...!

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.