3

IERC20 interface contains methods with uint256 datatype. If you try to call ink! wasm contract from Solidity (compiled by solang to target subtrate) you will have an issue.

interface IERC20{
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }
}

How to return u256 data type from rust ink! smart contract to support compatibility with IERC20?

1 Answer 1

3

The best way is to use ethnum crate: https://crates.io/crates/ethnum

Code example:

#[ink(message]
pub fn balance(&self, account : AccountId) -> [u128; 2] {
   let balance_u128 : u128 = self.balance_of(account);
   use ethnum::U256;
   let balance_u256: U256 = U256::try_from(b).unwrap();
   balance_u256.0
}

It works fine while you will call this contract method from Solidity wasm contract(compiled by solang to substrate target)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.