0

I am pretty new to the Ethereum and ERC20. I am willing to create an ERC20 token. I see that ERC 20 tokens can be transacted using the Ethereum addresses. However, I am wondering if it is possible to create an ERC20 token that is using custom address format. I basically have the idea to map user-recognisible names that can be mapped to actual addresses. So, for example jhonny333 maps to certain ethereum address. I guess that can be implemented on top of ERC20 token implementation, but then comes the question, where will the information of which address belongs to who be stored.

I am also wondering if there is a possibility to implement that address mapping directly in my token's smart contract. So, in other words as the title says: Is there a way to use Solidity to generate a token that uses custom addresses to send transactions?

4 Answers 4

0

You can simply trace into your sw the names of your user rewriting all the ERC20 function where some address is used in order to be able to accept a string, mapping this in a global mapping:

mapping(string=>address) addressTable;

For instance:

balanceOf(address user)

will become:

balanceOf(string user)

and your functions will be something like:

function balanceOf(string user) view public returns (uint256) {
  address userAddress;
  userAddress = addressTable[user];
  return( balance(userAddress);
}

each standard ERC20 function can be rewritten as such. The problem is that you must provide at least a separate function able to fill the mapping named addressTable in this example. Something like:

function registerUser(string user) public {
  if (addressTable[user] == 0) addressTable[user] = msg.sender;
 }

where each user can decide his own nickname once.

Of course this is a principle-explaining code only.I hope it can help.

2
  • 3
    If you change the function signatures it is no longer ERC20 Apr 15, 2020 at 6:48
  • You are definitively right, but I think this is the kind of answer he his looking for. Of course it is not an ERC20, but something borrowing the logic from the ERC20, using strings instead of Ethereum addresses.
    – Rick Park
    Apr 15, 2020 at 6:57
0

You can't directly tell the system which address to use. There are two ways contract addresses are created: CREATE and CREATE2 opcodes. With the regular CREATE you have very little control over the address: you can only control (a little bit) the nonce used for generating the address but that's it.

With CREATE2 you have a little more control over the address but still it's basically a hash of things so you can't choose the address freely.

The only thing I can think of is using a middleman contract which has some arbitrary identifiers for real regular addresses. So for example the contract might have a function signature function transfer(string identifier, uint amount) public where identifier can be jhonny333 for example. This function has a mapping between the identifier and the real address and it performs the actual (internal) transaction to the real ERC20 address. This of course doesn't create any real addresses but only a way for people to transact with identifiers instead of addresses.

You can read more about CREATE and CREATE2 for example here: How is the address of an Ethereum contract computed?

0

There is a service named ENS - Ethereum Name Service that allows mapping from names to addresses.

It requires some support from wallets to be able to resolve to addresses, but it was becoming popular among ethereum wallets.

0

You can simply implement a mapping from a string to an address. The string will be the username. That way you can identify people by their name. You'll have to create a setter function for that mapping.

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.