Need help with creating ERC223 token


#1

So, I am having a little bit of an issue with understanding the line:

uint public totalSupply = 1000000000 * (10**decimals);

What I am thinking is that is a supply of 1B, now if I was to say want a total supply of 10M tokens I would just erase two 0’s to make it 10000000? I don’t think it can just be that easy, or am I right?

Please any help with that would be great, and thank you ahead of time.


#2

You are right! That is all you would need to do. The line looks a little strange only because Solidity does not support fixed point numbers so you need a way to handle the decimal offset, which is the * (10**decimals) part.


#3

Okay thank you! That was a bit confusing. So even if I wanted to make say 8 decimal points I still wouldn’t have to worry about the (10**decimals) either right? Just leave that as is?


#4

And a few more things, the current line is also confusing to me. I see 2B, so If i say wanted to have 1 ETC = 1000 I would just change it too 40000000? Or am I wrong.

  // ICO price. You will need to do a little bit of math to figure it out
  // given 4 decimals, this setting means "1 ETC = 50,000 TKN"
  uint256 private priceDiv = 2000000000;

Then my final question would be on the following line, say if I wanted to allocate 1M tokens for myself
would I just simply put 1000000 instead of the 850M? Or do I have to put the remainder which is not being used for the ICO.

And for the ICO amount if I wanted to have a 5M ICO sale would I also simply erase the 150M and put 5000000? Sorry for any inconvenience and thank you ahead of time.

  constructor() public {
    // This is how many tokens you want to allocate to yourself
    balances[msg.sender] = 850000000 * (10**decimals);
    // This is how many tokens you want to allocate for ICO
    balances[0x0] = 150000000 * (10**decimals);
  }

#5

So if you want 8 decimals, all you would do is set

uint public decimals = 8;

Then you do not touch any of the (10**decimals) parts. If you are looking to set 1 ETC = 1000 tokens, and your token has 8 decimals. Then you would need to set the following:

uint256 private priceDiv = 10000000;

Because you want 0.001 Ether to equal 1 token, and the price is calculated in WEI. If you put in 0.001 Ether in the converter here you will see it equals 1000000000000000. So you need to set the price to take your decimal into account:

10000000 * (10^8) = 1000000000000000.

Not sure why this line of code does not have the * (10**decimals) part, I think that is why it is confusing - maybe @Neuron can let us know? :slight_smile:

Then for your last question, yes you simply need to amend those numbers as you see fit(of course take into account your total supply!)

Let us know how you get on, thanks!


#6

Okay, first off thank you with all the help, I know JS but Solidity doesn’t quite make sense to me, I tried looking it up and couldn’t find much of any help in the regions I needed, plus I could only find ERC20 which seems a bit different to me. But one final question, So like you said above, for the ICO and for my supply, if I want 1M for myself and 5M for the ICO would i just put 1M and 5M into the correct spots? Like what I am asking is, does that leave all the remaining balance in my contract address? Or should I put the actual tokens left not including my 1M in the ICO? This is the only thing that is holding me back now, as I do not want to make any mistakes while making my token. Thank you again for any help.


#7

doesn’t have decimals part there because I didn’t write it. If you are planning to launch your own token the least that you could do is understand how a token works and be able to modify 1-2 lines of code.

ETC is still young and needs real builders to help it grow. You can use Remix, possibly on a testnet, launch a bunch of contracts and play with them, see how it all works. This is the best way to learn!

This is how you can check your ideas about the price too, @jamesokb. Nobody gets coding right on the first try. So go ahead and experiment! Try your ideas, plug in a bunch of different numbers and see how it all works out. Good luck!


#8

that sounds about right. Still, you should try in Remix and let us know how it all worked out. You’ll be the first brave one to change token supply and token price compared to our guide :slight_smile: Please, when you’ve got it all sorted out, publish your final code here on this forum so others can learn from your experiments.

Let us know if you have further questions!


#9

Thank you @Neuron, I took a coding bootcamp course about year ago which taught me the MEAN stack, I am trying to teach myself Solidity, if you know of any good links for me to start I would appreciate that. Right now everything I find is mainly for ERC20 and I haven’t found anything not deprecated. I was going to just make a few dummy tokens for experimental use only but I really don’t want to have to waste any ETC if you know what I mean.

As for posting my final code I would be happy with giving any information, I am planning to create a social media type platform with a ETC based tipping system. I’m not even sure how I am going to go about doing that but if you guys may have some tips or links for me to follow I am all ears. Thanks again @samr and @Neuron.


#10

Okay, so this is what I have came up with. I want my token to have 8 decimals, a total supply of 25M, I have my Saturn address as the wallet address(unless you guys think I should change that),I want my ICO to be 1 ETC = 1000 of my tokens, I want to save 1M tokens for myself, and I want to have 5M for the ICO sale.

First off is that even a good ICO amount or what seems about right for you guys, I think that is actually a really high asking price, but I would like your guys input. Thanks again for all the help.

uint public decimals = 8;
  // total supply of the token
  // for example, for Bitcoin it would be 21000000
  uint public totalSupply = 25000000 * (10**decimals);

  // Treasure is where ICO funds (ETH/ETC) will be forwarded
  // replace this address with your wallet address!
  // it is recommended that you create a paper wallet for this purpose
  address private treasury = 0xF365B7EFB903797CfCF4e64f652D29a8A6260158;
  
  // ICO price. You will need to do a little bit of math to figure it out
  // given 4 decimals, this setting means "1 ETC = 50,000 TKN"
  uint256 private priceDiv = 10000000;
  
  event Purchase(address indexed purchaser, uint256 amount);

  constructor() public {
    // This is how many tokens you want to allocate to yourself
    balances[msg.sender] = 1250000 * (10**decimals);
    // This is how many tokens you want to allocate for ICO
    balances[0x0] = 5000000 * (10**decimals);
  }

#11

Nice, great to hear! As Neuron said I would just go for it, and fiddle around until you get it right. It will be better for the future of your project, make mistakes now and learn how to fix them. Remember you can always start by using testnet.

Good luck!


#12

For this purpose I would suggest using Ganache for a local testnet, or use metamask + rinkeby for a public testnet with remix.

Not aware of any good guides, this field is still young so people just figure things out on their own. Trial and error is the best teacher! Gotta be committed to spend some time on learning, no easy courses, although I heard that Cryptozombies is OK.


#13

See how I edited your post? Please consult with this guide to learn proper markdown formatting :heart:


#14

I think your pricediv is wrong. Go ahead, experiment, and find out the right value


#15

Thank you @Neuron, will check that out, and now I know how to use the Preformatted text.:vulcan_salute:


#16

Okay @Neuron and @samr , I have been making smart contracts on ropsten to get the feel of everything and turns out I have an issue which I do not know what I did wrong.

So what I have came up with is this, I have found a way to set up a smart contract which awards the sender of 1000 tokens but when I send using 1 gwei it will fail but when I send using 10 gwei it goes through . Is there something I am missing here? Or would this not even matter once the actual smart contract is deployed? Again, thank you for all the help you guys have gave me so far, here is the follow code:

uint public decimals = 8;  // 8 decimal spots
uint public totalSupply = 25000000 * (10**decimals);  //25M tokens
uint256 private priceDiv = 10000000;  // 1 ETC = 1000 tokens

#17

You mean when you set the gas price to 10 GWEI it works but not with 1 GWEI?

I think this sounds right, remember there are actually two transactions happening here and you have to provide enough Gas for both. First to send your Ether to the ICO contract address & then the smart contract needs to send you your tokens.


#18

Yes @samr thats whats exactly whats going on, should that be happening? Once the final contract is finished would that even matter? Thanks again for all the info and any info you may give me again.


#19

Pretty sure that is what should happen, if you don’t provide enough gas for two transactions then it will fail.


#20

Thank you @samr, I think I should be ready to publish it soon. Thanks again for the help from you and @Neuron .