Skip to content
On this page

OP_PUSHDATA2 ​

INFO

Opcode number: 77
Byte representation: 0x4d
Short description: Read the next 2 bytes as N. Push the next N bytes as an array onto the stack.

The OP_PUSHDATA2 opcode will read the 2 bytes that follow it and interpret them as an integer. It will then push the next number of bytes this integer specifies onto the stack. Because it reads 2 bytes and inteprets them as a number, this opcode can push any number of bytes from 0 to 65,535, though consensus rules only allow at most 520 bytes in one push. Note that for any number of bytes between 76 and 255, it is more efficient (and required by standardness rules) to use OP_PUSHDATA1, and for any number of bytes under 76, opcodes in the OP_PUSHBYTES family, or more specific opcodes where applicable (see minimal push operations).

OP_PUSHDATA2 is part of a group of 3 opcodes that push a custom, user-specified number of bytes onto the stack (its sibling opcodes are OP_PUSHDATA1 and OP_PUSHDATA4).

Example ​

This example pushes 400 bytes to the stack.

shell
# ASM script
OP_PUSHDATA2 190 a4b5c6d7e8f90a1b2c3d4e5fa0b1c2d3e4f56a7b8c9da0b1c2d3e4f57a8b9c0d1e2fa3b4c5d6e7f89a0b1c2d3e4fa5b6c7d8e9f01a2b3c4d5e6fa7b8c90d1e2fa4b5c6d7e8f92a3b4c5d2ea4b5c6d7e8f90a1b2c3d4e5fa0b1c2d3e4f56a7b8c9da0b1c2d3e4f57a8b9c0d1e2fa3b4c5d6e7f89a0b1c2d3e4fa5b6c7d8e9f01a2b3c4d5e6fa7b8c90d1e2fa4b5c6d7e8f92a3b4c5d2ea4b5c6d7e8f90a1b2c3d4e5fa0b1c2d3e4f56a7b8c9da0b1c2d3e4f57a8b9c0d1e2fa3b4c5d6e7f89a0b1c2d3e4fa5b6c7d8e9f01a2b3c4d5e6fa7b8c90d1e2fa4b5c6d7e8f92a3b4c5d2ea4b5c6d7e8f90a1b2c3d4e5fa0b1c2d3e4f56a7b8c9da0b1c2d3e4f57a8b9c0d1e2fa3b4c5d6e7f89a0b1c2d3e4fa5b6c7d8e9f01a2b3c4d5e6fa7b8c90d1e2fa4b5c6d7e8f92a3b4c5d2ea4b5c6d7e8f90a1b2c3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