How to I add items to a chest and spawn it with those items in it with a command block? [closed]

An example to give yourself a chest with an item already inside it is as follows:

/give @p chest{BlockEntityTag:{Items:[{Slot:11b,id:"minecraft:stone",Count:1b}]}}
  • BlockEntityTag = What nbt the chest will have
  • Items = The items, how many items and the slot it's in.
  • Slot = The slot the item will be in. This ranges from 0-26.
  • id = The type of item.
  • Count = The number of items.

Slot, id and Count are all required, or it will not work.

To give yourself a chest with more items, you'll need add this after the first set of nbt within the square brackets:

,{Slot:12b,id:"minecraft:grass_block",Count:47b}

An example is as follows:

/give @p chest{BlockEntityTag:{Items:[{Slot:11b,id:"minecraft:stone",Count:1b},{Slot:12b,id:"minecraft:grass_block",Count:47b}]}}

These commands are for 1.13 Java Edition. Here is an example for 1.12:

/give @p chest 1 0 {BlockEntityTag:{Items:[{Slot:11b,id:"minecraft:stone",Count:1b}]}} 

Notice the only thing I changed is I put the count and the type before the nbt.