This is a KIND 5391 event created on 2024-03-25 23:51:32 (8 months, 1 week ago). Debug this event chain.
{ "id": "a84de62d77b3e1dd1ff9b6b88b561213d5996672a98fcefe669a3666e07561d1", "pubkey": "a029df4a2c4a042f4b23a0d6197fd9680805327e023eb1705c70d13db9821a3d", "created_at": 1711410692, "kind": "5391", "tags": [ [ "e", "67c2163ef886642d4e3a0c9d99c4b056a0176320a88b3a502595d1bf9f8b15dc", "wss://dashglow-test.nostr1.com", "root" ], [ "m", "text/html" ], [ "alt", "This is a binary chunk of a web-based video game. Play the full game at https://crashglow.com/game/nevent1qqsx0ssk8mugvepdfcaqe8vecjc9dgqhvvs23ze62qjet5dln793thqpremhxue69uhkgctndpnkcmmh946x2um59ehx7um5wgcjucm0d5q3vamnwvaz7tmjv4kxz7fwwpexjmtpdshxuet5qy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszymhwden5te0wfjkcctev93xcefwdaexwqg5waehxw309aex2mrp0yhxummnw3ezumt9qyxhwumn8ghj7mn0wvhxcmmvqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzyzsznh62939qgt6tywsdvxtlm95qspfj0cpravtst3cdz0desgdr6qcyqqqqqqgn47xm6" ], [ "index", "0" ], [ "x", "a33194f438851920cc43d59c61a386b79adcc5a55b0b64667386cd8f43baaab0" ] ], "content": "PCFET0NUWVBFIEhUTUw+CjxodG1sPgoKPCEtLSBIRUFERVIgLS0+CjxoZWFkPgoKPG1ldGEgY2hhcnNldD0iVVRGLTgiPgoKPHRpdGxlPlRlc3Q8L3RpdGxlPgoKPHNjcmlwdCB0eXBlPSJ0ZXh0L2JpdHN5R2FtZURhdGEiIGlkPSJleHBvcnRlZEdhbWVEYXRhIj4KVGVzdAoKIyBCSVRTWSBWRVJTSU9OIDguOQoKISBWRVJfTUFKIDgKISBWRVJfTUlOIDkKISBST09NX0ZPUk1BVCAxCiEgRExHX0NPTVBBVCAwCiEgVFhUX01PREUgMAoKUEFMIDAKMCw4MiwyMDQKMTI4LDE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