How to use U256 and U128 with std::token::* functions

Hi guys!!!

On this topic, we discussed numbers greater than u64 and @furnic suggested using std::u128::U128 and std::u256::U256 to make the “token standard”.

Today I wanted to deploy test tokens like UNI, WETH, LINK etc with decimals of 18 and ran into if we change all of u64 to std::u256::U256 in my token contract then some important from std::token like burn, transfer_to_address, mint and mint_to_address does not work because they are waiting for u64 argument and also not least function context::balance_of also returns u64.

Please tell me how can I make a token standard with decimals 18
Thanks!!

6 Likes

I’m afraid that is not possible without making multiple separate mints or transfers. Transfers to addresses use the tro opcode under the hood and that opcode only accepts an amount of coins that fits in a single register which is only 64 bits. So, if you want to mint or transfer more than 2^64 - 1 coins, the only way to do that is by breaking your operations into multiple ones such that each operation mints or transfers no more than 2^64 - 1 coins.

2 Likes

I researched this and found out that in some blockchains, for example, the decimal of the wrapped ether is 8. I think it does not matter, I will just issue my tokens with decimal 8

To expand on @mohammadfawaz’s reply, you could perform this “batching” in a loop in your contract, or write a sway script which makes multiple calls to your contract.

Additionally, the limitation to using u64::max() is not just for transfers, but for all native operations in the FuelVM as the VM’s word size is 64 bits.
As a result, any larger sizes can only be implemented in libraries, and operations which utilize these larger sizes must be implemented at the application layer.

3 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.