# Declare ERC20 in constructor fails

**URL:** <https://forum.openzeppelin.com/t/declare-erc20-in-constructor-fails/6167>\
**Category:** Support\
**Tags:** erc20\
**Created:** [March 9, 2021, 3:52pm UTC](https://forum.openzeppelin.com/t/declare-erc20-in-constructor-fails/6167 "2021-03-09T15:52:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aymane](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Aymane](https://forum.openzeppelin.com/u/Aymane)\
**Post date:** [March 9, 2021, 3:52pm UTC](https://forum.openzeppelin.com/t/declare-erc20-in-constructor-fails/6167/1 "2021-03-09T15:52:07Z")

</div>

I made 2 versions of my code. One is returning an error and the other one is working.  
However the 2 code are supposed to do the asme thing.

I’m working on Remix with Solidity 0.8.0.

Code 1 :

```
address tokenAddress;

//Setting the creator address on deployment
address creator;

constructor(address _tokenAddress) ERC721("RAMEN CARD", "RMC") {
    tokenAddress = _tokenAddress;
    creator = msg.sender;
}

function retourne() public view returns(address){
    return tokenAddress;
}

TokenInterface RMN = TokenInterface(tokenAddress);

function send() public {
    RMN.transferFrom(0x1002CA2d139962cA9bA0B560C7A703b4A149F6e0, 0x1002CA2d139962cA9bA0B560C7A703b4A149F6e0, 100);
}

```

Code 2 :

```
address tokenAddress = 0x031A4e59A6faDD01F0D129fD09E6B8d94268a46D;
TokenInterface RMN = TokenInterface(tokenAddress);

//Setting the creator address on deployment
address creator;

constructor() ERC721("RAMEN CARD", "RMC") {
    creator = msg.sender;
}

function send() public {
    RMN.transferFrom(0x1002CA2d139962cA9bA0B560C7A703b4A149F6e0, 0x1002CA2d139962cA9bA0B560C7A703b4A149F6e0, 100);
}

```

Code 2 is working and Code 1 is not.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [March 10, 2021, 1:51am UTC](https://forum.openzeppelin.com/t/declare-erc20-in-constructor-fails/6167/2 "2021-03-10T01:51:40Z")

</div>

Hey, how about changing the code as the following:

```auto
TokenInterface RMN;
constructor(address _tokenAddress) ERC721("RAMEN CARD", "RMC") {
    tokenAddress = _tokenAddress;
    creator = msg.sender;
    RMN = TokenInterface(tokenAddress);
}

```

---

<div class="post-metadata">

**Author:** ![Aymane](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Aymane](https://forum.openzeppelin.com/u/Aymane)\
**Post date:** [March 11, 2021, 10:49pm UTC](https://forum.openzeppelin.com/t/declare-erc20-in-constructor-fails/6167/3 "2021-03-11T22:49:55Z")

</div>

Thanks it worked 😛
