How to set the ERC20 token price in respect to ether in solidity

0 votes

Hi, all

I have a input field in my DAPP where user can input ETH and click the submit button to get token worth ETH..How to calculate the token price in ether and get the token and show it in DAPP..

Token Price is 0.10 cents

function getPrice() public pure returns(uint256) {
     uint256 totalEther = uint256(225800608429140) / uint256(10**18);
     uint256 result = uint256(231481480000000) * 10**18;
     uint256 totalTokens = result / 1 ether;
    //  _totalEther =  totalEther;
     return totalTokens;
 }

but this isn't working.

Nov 7, 2020 in Blockchain by jas
• 120 points
3,824 views

1 answer to this question.

0 votes

Hi, @Jas,

I would suggest you go through this https://blockgeeks.com/guides/ethereum-token/

answered Nov 9, 2020 by anonymous
• 10,500 points

Related Questions In Blockchain

0 votes
1 answer

How to set token price in solidity?

We know that 1 Ether = 1018 wei, ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,310 points
5,677 views
0 votes
1 answer

How to save complex object in the contract in solidity

You can't pass objects when initiating a ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,190 points
2,241 views
0 votes
1 answer

How to set the hex-encoded data field in a Web3j Ethereum transaction?

You can use the "data" field of ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,190 points
1,925 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,008 views
0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,100 points
2,525 views
0 votes
1 answer
0 votes
2 answers

Getting error while Initialising the Blockchain

Hello, @Edureka, You have two options: Execute with sudo. This ...READ MORE

answered Sep 17, 2020 in Blockchain by Roshni
• 10,500 points
807 views
0 votes
2 answers

Code to change owner

Hi, @Wilson, U have to write the require ...READ MORE

answered Oct 5, 2020 in Blockchain by Rajiv
• 8,910 points
816 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP