I need to create a ERC721 contract where ERC721 constructor properties (name, symbol) are not provided directly but they are calculated from the new constructor parameters. I am trying like this but it does not work

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC721 {
        string someparameter
    )  {
        // transform "someparameter into two variables with string manipulation,
        // let's say "somparameterName" and "someparameterSymbol"
        super(somparameterName, someparameterSymbol)

Is this possible? It seems like it only allows using ERC721(_name, _symbol) after constructor(string someparameter) and before the body of the constructor ({...})


1 Answer 1


You could create a function that parses the input and call the constructor with the result

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.0 <0.9.0;

contract A  {
    string public b;

    constructor(string memory a) {
        b = a;

contract B is A {
    constructor(string memory x) A(foo(x)) {


    function foo(string memory z) internal pure returns (string memory) {
        return string(abi.encodePacked(z, "polo"));
  • 1
    damn, didn't know this was possible. Thanks! :) Will delete my answer Feb 6, 2022 at 17:09

Your Answer

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

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