Difference of balance keyword between different blockchain - solidity

I know that the address(this).balance shows the eth balance of the target contract.
Does the balance keyword return the balance of the native currency of that blockchain, or always returns balance of the contract's eth's?
If my SC is deployed on the polygon, does the balance keyword return the matic balance of my contract?

It always returns native balance of the address on the specific network where the contract is deployed.
ETH on Ethereum
MATIC on Polygon
BNB on Binance Smart Chain
etc.

Related

I need to understand below smart contract code

Can you help me explain below smart contract code I found on tomb finance, tomb.sol contract?
// Initial distribution for the first 24h genesis pools
uint256 public constant INITIAL_GENESIS_POOL_DISTRIBUTION = 11000 ether;
// Initial distribution for the day 2-5 TOMB-WFTM LP -> TOMB pool
uint256 public constant INITIAL_TOMB_POOL_DISTRIBUTION = 140000 ether;
// Distribution for airdrops wallet
uint256 public constant INITIAL_AIRDROP_WALLET_DISTRIBUTION = 9000 ether;
Why do they distribute ether for the pools?
Why ether?
Can they do that?
What exactly is the value of 1 ether?
If they had deployed this on BNB Chain, will this code will change?
This snippet alone doesn't distribute any ether, it only declares 3 constants. It's likely that there's some other functions in the code, that wasn't shared, that make use of these constants.
ether in this case is a Solidity global unit. No matter on which network you deploy the contract, it multiplies the specified number by 10^18 (or 1000000000000000000). Current version of Solidity (0.8) is not able to store decimal numbers, so all native and ERC-20 balances are stored in the smallest units of the token. In case of native tokens (ETH on Ethereum, MATIC on Polygon, ...), that's wei. And 10^18 wei == 1 ETH (or 1 MATIC, etc - depending on the network).
If this code was deployed on other EVM network (such as Binance Smart Chain), the ether unit is the same. It doesn't work with ETH tokens, it "just" multiplies the number.

Solidity, uniswapV3 swap

I have swept on uniswapV3 weth to DAI. The code first gets weth via contract and latter gets DAI on Uniswap.
The change is 0.005weth = 173.68 DAI
Is this normal??, I really don't understand this change and don't know if I did somthing wrong.
here is the tx: https://goerli.etherscan.io/tx/0x92f4d746b89f65a50e49657fb1fbe0a1d1446c1881210beac56ff5e9a7d90567

i got error with gas limit 1000000 (gas required exceeded limit)

I am new in smart-contract, following 1 tutorial, he used 1000000 as gas limit which was fine before but today I faced this error (out of gas), after some searched I found and I replaced 1000000 with 3000000,
my question is, why code worked with 3000000 but show the error with 1000000 ??
thanks
Gas is the term for the amount of ether (ETH) – the native cryptocurrency of Ethereum – required by the network for a user to interact with the network.
So its simple this time around the interaction you did with blockchain must have been more complicated. So it required more operation as a result more gas fee.
Check out this link to learn more about gas Gas in ethereum
Yeah of course it's the most important thing when you type or code smart contracts, so every function you type in smart contract costs gas, and you can calculate it throw https://wiki.learnblockchain.cn/OPCODE_Gas.pdf , after knowing how much gas costs you will do this Calculation
gas used * gas price * 0.000000001
and you'll know gas price from https://etherscan.io/ .

exchange own ERC20 token to another token in smart contract for Game

I want to deploy a smart contract (ERC20) for the game,
so the purpose is to keep points.
when someone enters the game, we will ask for some crypto coin (ex. ETH) and give some of our own points
while playing the game, the user will earn some points.
Then that user can get crypto coins (ex. ETH) from that points.
I can write a smart contract to manage points.
But I wonder if I can have a function to exchange our points to existing crypto coins (ex ETH) inside of our smart contract.
Does someone know the right way to do it?
You can calculate the amount of ETH based on a price, and then use the transfer() native function of address payable type.
mapping (address => uint256) pointBalances;
// 1 point for 100 wei, assuming the points have 0 decimals
uint256 price = 100;
function sellPoints(uint256 _amount) external {
require(pointBalances[msg.sender] >= _amount, "Insufficient balance");
pointBalances[msg.sender] -= _amount;
uint256 weiAmount = _amount * price;
payable(msg.sender).transfer(weiAmount);
}

Uniswapv2 addLiquidity Decimal error in Remix (Bignumber)

I'm testing Uniswapv2 for a project and am getting this error:
transact to UniswapV2Router02.addLiquidity errored: Error encoding arguments: Error: invalid BigNumber string (argument="value", value=".004", code=INVALID_ARGUMENT, version=bignumber/5.1.1)
The Uniswapv2 code is normal and unedited. I tested these number on Uniswap itself to make sure the numbers worked before I tried them in Remix. These are what I tried to pass:
tokenA: 0xc778417e063141139fce010982780140aa0cd5ab (WETH since I can't find ETH address)
tokenB: 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 (UNI)
amountADesired: 0.004
amountBDesired: 0.03
amountAMin:1
amountBMin:2
to: 0xd50eCE9501a1f63e449DbBBbBdc5CB59f3e2c231
deadline: 255
Solidity contracts don't take decimal arguments. Instead, you need to pass the amount of smallest units.
WETH (note - you have an incorrect address in your question) has 18 decimals, UNI has 18 as well.
1 WETH is 1000000000000000000 (or 10^18) units.
So if you want to pass 0.004 WETH in the argument, you need to input the number 4000000000000000 (which is 0.004 * 10^18).
Note: ETH is the native currency of the Ethereum network, so there is no token address for ETH. Uniswap v2 Router 2 has a function addLiquidityETH() for when you want to add liquidity to a pair of a token to ETH.