Uniswapv2 addLiquidity Decimal error in Remix (Bignumber) - solidity

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.

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.

Difference of balance keyword between different blockchain

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.

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/ .

is there any way for solidity 0.4.24 get bytes data from call

I am trying to follow this trick.
https://blog.polymath.network/try-catch-in-solidity-handling-the-revert-exception-f53718f76047
For solidity version 5 all works and I can do this:
(bool success, bytes memory returnData) =
address(token).call(...)
For solidity version 4 I can do only this:
(bool success) =
address(token).call(...)
If I am trying get returnData in v4 I get this err
TypeError: Not enough components (1) in value to assign all variables
(2).
is there any way to get returnData for Solidity v 4 ? Without double call?
I need this data for case not to make a double call when I need to check the view function, this can be called or not on contracts.
Yes, this is only possible in version 5 and newer
https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html

Difference between this 2 values?

In my js file I call a send transaction to the smart contract, so what is the difference between values :
instance.multiply.sendTransaction(val,{ from: accounts[0], gas : 300000} and instance.multiply.sendTransaction({ from: accounts[0], gas : 30000, value : val},
I am passing first one to the function as an argument and the second is accessible in the function just by msg.value ?
In your first code snippet, you're passing val as an argument to a function.
In the second code snippet, you're not passing any arguments, but you're sending val wei in the transaction. Yes, the contract, can see how much wei was sent by looking at msg.value, but importantly there was also a transfer of ether. (10**18 wei == 1 ether.)
So the key differences between the two are:
One passes a value as an argument, and the other doesn't.
One sends some ether with the transaction, and the other doesn't.
Proper Syntax for web3.eth.sendTransaction
web3.eth.sendTransaction(transactionObject [, callback])
Second one works fine instance.multiply.sendTransaction({ from: accounts[0], gas : 30000, value : val}, and should.
The format of sendTransaction is sendTransaction({from: eth.accounts[0], data: code, gas: 100000}).
from: String - The address for the sending account. Uses the
web3.eth.defaultAccount property, if not specified.
to: String - (optional) The destination address of the message,
left undefined for a contract-creation transaction.
value: Number|String|BigNumber - (optional) The value transferred
for the transaction in Wei, also the endowment if it's a
contract-creation transaction.
gas: Number|String|BigNumber - (optional, default:
To-Be-Determined) The amount of gas to use for the transaction
(unused gas is refunded).
data: String - (optional) Either a byte string containing the
associated data of the message, or in the case of a
contract-creation transaction, the initialisation code.
For more See: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction