You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's currently impossible to have immutable strings in a contract. This code fails:
contract MyToken {
string immutable public name;
constructor(string memory _name) {
name = _name;
}
}
with the compilation error
Error (6377): Immutable variables cannot have a non-value type.
But this code works:
contract MyToken {
string constant public name = "Some Name";
}
In an ideal world, they would produce the exact same runtime bytecode (if the constructor argument of the first one was "Some Name").
Motivation
Most base ERC20 token implementations rely on storage for the name and symbol of the token because it's the only way for people to be able to extend their implementation and select a name for their own token. But in reality those could very well be constants (or immutable).
If Solidity allowed for immutable strings, then these implementations would use that instead and it would result in big gas savings especially for factories that deploy tokens (120k gas per token)
would store the immutable someImmutable the same way as how constants are currently stored in the bytecode (and made accessible with a getter if the immutable is public)
Backwards Compatibility
This should be 100% backwards compatible. All contracts that previously compiled would still compile with the same bytecode.
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Abstract
It's currently impossible to have immutable strings in a contract. This code fails:
with the compilation error
But this code works:
In an ideal world, they would produce the exact same runtime bytecode (if the constructor argument of the first one was "Some Name").
Motivation
Most base ERC20 token implementations rely on storage for the
name
andsymbol
of the token because it's the only way for people to be able to extend their implementation and select a name for their own token. But in reality those could very well be constants (or immutable).If Solidity allowed for immutable strings, then these implementations would use that instead and it would result in big gas savings especially for factories that deploy tokens (120k gas per token)
Specification
Ideally the syntax
would store the immutable
someImmutable
the same way as how constants are currently stored in the bytecode (and made accessible with a getter if the immutable is public)Backwards Compatibility
This should be 100% backwards compatible. All contracts that previously compiled would still compile with the same bytecode.
The text was updated successfully, but these errors were encountered: