###### tags: `Mesa` `Tech`
# Data Types from Smart contract to Front-End
## Solidity: uint256
On solidity only int exists, float are no supported out of the box. Mostly
uint256 is used, a unsigned integer which used 256 bits. Max value is 115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,457,584,007,913,129,639,935.
https://www.wikiwand.com/en/256-bit_computing
https://ethereum.stackexchange.com/questions/29946/what-is-uint256/29948
## On the graph: BigInt
Adam uses BigDecimals?
The graph takes the uint256 and stores this in the database as strings, the datatype is then called BigInt

src: https://thegraph.com/docs/assemblyscript-api#built-in-types
## BigDecimals
More
https://github.com/graphprotocol/graph-ts/issues/98
## For Mocking Amount of token to replicate data from the graph
int = 1
decimals = 18
amount = BigNumber.from(int).mul(BigNumber.from(10).pow(BigNumber.from(decimals))
## On the FE/Typescript: BigNumber from ethers

https://docs.ethers.io/v5/api/utils/bignumber/
To correctly show a amount of token as string on the FE use:
ethers.utils.formatUnits(BigNumber, decimals of ERC-20)
To convert a string of a amount into a BigNumber use:
ethers.utils.parseUnits(string, decimals of ERC-20 )
## ERC-20
For uint256 as a amount in ERC-20, the decimal information has to be known. standard is 18 decimal. So 1 token is represented as 1 000 000 000 000 000 000 on a smart contract as uint256. BUT USDT and USDC has only 6 decimals!
So one 1 USDC is represented as 1 000 000 on the smart contract!
To have this value correct, we need to know the decimal of the token and this info is stored on ERC-20 token itself as "decimals"
# Best solution?
## Smartcontract
tokenIn: uint256 (5000000000000000) <- 0.5 TKN with 18 decimals
tokenInDecimal: uint256 (18), but could be range [0-18]
## Subgraph
tokenIn: uint256 -> BigInt "5000000000000000"
tokenIn: uint256 -> BigDecimal "5000000000000000"
tokenInDecimal: uint256 -> int
## Mesa JS
Idea is to have on this level both, correct integer and convert to a decimal for display:
tokenIn:
string "5000000000000000" -> BigNumber (5000000000000000) (Used for calulcation in the FE)
tokenInDecimal: string "18" -> int (18)
tokenInDisplay:
tokenIn string x tokenInDecimal int
-> Number (0.5) (Used for display in the FE)
## Mesa FE
* For show amount in FE, use tokenInDisplay
* For calculation with the same precision as Smart Contract use tokenIn and tokenInDecimal
As we don't need fraction on token amounts, I think BigDecimals have no use to us. But maybe this is very much non issue. So you have 0.5 of a token, which is 5000000000000000 as int. If you store this as BigInt or BigDecimal you store 5000000000000000. Then you read the graph, you will get "5000000000000000" and this you can either convert into BigNumber, or to a Number