In Solidity, if we get the block.number it returns type uint256 (alias uint), so I use type uint256 to store the block number in a Solidity contract.

However, in ink! the equivalent u256 is not allowed (as mentioned here), as only up to u128 is supported, and they suggest alternatives like using a wrapper around [u64; 4].

Based on this question it appears that ink! cross-chain contract calls using XVM and XCM as it is not yet supported, however in the answer to this question they highlight it is possible to do cross-contract calls into a Solidity contract from an ink! contract and vice versa from an ink! contract to a Solidity contract too on the same chain.

So if we made a cross-contract call on the same chain from an ink! contract to a function in a Solidity contract that fetched and returned the latest block number of type uint256 value, what type should we store that as in the ink! contract where it gets returned to?

Note that when dealing with Substrate-based chains we use u32 as shown here.

  • 1
    To my knowledge there is still no working version of XVM. Why don't use [u8; 32] for u256, and impl From for your needs? In a similar manner, the EVM type address in Astar XVM is actually [u8; 20] which is equivalent for H160
    – Maario
    Jul 18, 2023 at 15:03
  • @PierreOssun mentioned that this shows how to decode in ink! a call to a getter in Solidity github.com/AstarNetwork/ink-xvm-sdk/blob/… Jul 18, 2023 at 22:20

1 Answer 1


In ink! you can use self.env().block_number() or Self::env().block_number() in the constructor.

If you want to use XVM (only available in Shibuya) and query an solidity contract, you can deploy a solidity contract that returns the block number and call it like this:

            // get selector of the function from metadata
            const SELECTOR: [u8; 4] = hex!["18160ddd"];

            let mut encoded = SELECTOR.to_vec();
            let input = [];

            let result = self.env().extension().xvm_call(

            ink::env::debug_println!("xvm_call result: {:?}", result);

            if let Ok([Token::Uint(int)]) = ethabi::decode(
                &result.expect("xvm_call failed"),
            } else {
                panic!("failed to decode xvm_call result")

Source: https://github.com/AstarNetwork/ink-xvm-sdk/blob/18944607edb83a61e9a016eb588c5ee0804f2c70/contracts/erc20/lib.rs#L53


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.