When you compile your Sway code using the forc build command, it generates a bytecode file. This binary file contains the compiled code that the Fuel Virtual Machine (FuelVM) will interpret and execute.
For example, consider the following smart contract:
contract;use std::b512::B512;abi EchoValues {fnecho_u8(value:u8) ->u8;fnecho_str_8(value:str[8]) ->str[8];fnecho_str(value:str) ->str;fnecho_tuple(tuple: (u8, bool, u64)) -> (u8, bool, u64);fnecho_b512(input:B512) ->B512;fnecho_u64(value:u64) ->u64;}implEchoValuesforContract {fnecho_u8(value:u8) ->u8 { value } // Avoid executing this function; it is currently unsupported. // Refer to: https://github.com/FuelLabs/sway/issues/5110 for more details. // The function is defined here to include the type 'str' in the ABI, // ensuring Typegen can accurately interpret it. // For further information, see: https://github.com/FuelLabs/fuels-ts/issues/1469fnecho_str(value:str) ->str { value }fnecho_str_8(value:str[8]) ->str[8] { value }fnecho_tuple(tuple: (u8, bool, u64)) -> (u8, bool, u64) { tuple }fnecho_b512(input:B512) ->B512 { input }fnecho_u64(value:u64) ->u64 { value }}
After running forc build, a binary file will be generated with the following content:
At first glance, the content appears unreadable. However, forc provides a helpful interpreter for this bytecode: the forc parse-bytecode command. This command takes the binary data and outputs the equivalent FuelVM assembly:
When deploying your smart contract using the SDK, the binary file plays a crucial role. It is sent to the FuelVM in a transaction, allowing the FuelVM to interpret and execute your smart contract.