I want to custom ERC20 tokens based on user input.
I can achieve this in two ways
-
create smart contract that will create new instance of token contracts with details provided by client.
Doing so, the creator of contract is marked as the parent contract and I'll have to transfer the custom tokens from parent contract to the
msg.sender
after token creation. How do I make the child contract know that the creator istx.origin
? Can I usedelegatecall
to achieve this? If so how? -
use
ethers.js
to create token. This will remove the problems as mentioned1.
but i'll need to find a way to keep track of the tokens created (make another transaction to store the data)
What is the best way to do this?
Best Answer
You don't need to use tx.origin or delegatecall(will not work).
Just change the constructor of the child contract by adding a new parameter e.g.
And in the Factory contract (Parent) use msg.sender e.g.
And now you have the message sender in your child contract and you can use it as you like.
tx.origin could do the same but it has security risks . Therefore it is better to pass the message sender as a parameter
The benefits of your (2) solution is that you can update and change future contracts.
You don't need 2 transactions, you could deploy 1 Register Smart Contract that store the information you need and in the constructor of your custome ERC20 contract, call the register Smart contract to register the token.