Web3JS Online
Viem Online
Webhooks, Alerts, and a simple API.
The slice function in the viem library allows you to extract a section of a hex or byte array, specified by a start and end offset. The function takes three arguments: the value to slice, the start offset, and the end offset. The start and end offsets are optional, and if not provided, the function will use the default values of 0 for the start offset and the length of the value for the end offset.
The slice function is useful for extracting a section of a hex or byte array, and it allows you to specify the start and end offsets, as well as an optional strict option to ensure that the end offset is inclusive of the bounds of the data.
The slice function returns a new hex or byte array containing the section of the original value specified by the start and end offsets. If the end offset is not provided, it will be inferred from the length of the value. The function also takes an optional options object that can contain a strict property, which defaults to false. If strict is true, the end offset must be inclusive of the bounds of the data. If the end offset is out-of-bounds, an error will be thrown.
Here are some examples of using the slice function: