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 6, 2020 in Blockchain by jas
• 120 points
214 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,400 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,300 points
1,085 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,130 points
746 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,130 points
676 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,830 points
474 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
1,415 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,400 points
124 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,880 points
97 views