So I used a command block in 1.16.4 to summon a villager who sells dirt with custom name of 'DIRT BLOCK'. Then I /give myself the dirt block also with the name 'DIRT BLOCK' , I can do the trade at the first time, but as I closed the GUI of villager trading, and drop the item, I can't trade it with them anymore.
Below is my villager code
summon villager ~ ~1.5 ~ {VillagerData:{profession:librarian,level:5,type:plains},Invulnerable:1,NoAI:1,Offers:{Recipes:[{buy:{id:dirt,Count:1,maxUses:99999,tag:{display:{Name:"\"DIRT BLOCK\""}}},sell:{id:stone,Count:1,maxUses:99999}}]}}
and below is the /give
code I wrote
/give @s dirt{display:{Name:"\"DIRT BLOCK\""}} 64