Is it possible to detect the block number that the transaction included within solidity? For example somebody transfer me some eth or token, can I know the block number of the transaction?
Any Solidity method call that changes the state is a transaction. That transaction is composed of possibly multiple atomic operations. To log or return the block info of that transaction, you could use
block.number. You also have access to many other handy global properties. This is possible because that method call can only take effect on the state once the block that the transaction belongs to is mined. And upon mining, those properties expose all that info about that block. If you want to figure out the block number of any TX outside the realms of Solidity, you could use EthersJS or Web3JS and get that info as follows:
const provider = new ethers.providers...; provider.getTransactionReceipt(txHash).then(tx => console.log(tx.blockNumber))
web3.eth.getTransactionReceipt(txHash, tx => console.log(tx.blockNumber))