Skip to content

Instantly share code, notes, and snippets.

@Ifeanyi-Ani
Created August 14, 2023 07:25
Show Gist options
  • Save Ifeanyi-Ani/eb9b8a36dcb752ba383c33251e154289 to your computer and use it in GitHub Desktop.
Save Ifeanyi-Ani/eb9b8a36dcb752ba383c33251e154289 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.9+commit.e5eed63a.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract EtherConverter {
uint256 public weiFactor = 10**18; // Conversion factor from ether to wei
uint256 public gweiFactor = 10**9; // Conversion factor from ether to gwei
function etherToWei(uint256 _etherValue) public view returns (uint256) {
return _etherValue * weiFactor;
}
function etherToEther(uint256 _etherValue) public view returns (uint256) {
return _etherValue;
}
function etherToGwei(uint256 _etherValue) public view returns (uint256) {
return _etherValue * gweiFactor;
}
}
@Ifeanyi-Ani
Copy link
Author

Primitive Data Types in Solidity
Challenge
Write a smart contract that takes some ether from the user. Find out its value in units of:

wei
ether
gwei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment