# Example PyTeal name/ID validity check

The following PyTeal code can be used to validate that the specified NFD name matches the passed NFD App ID and that it's an authentic NFD.

```python
# is_nfd_id_authentic composes the name lookup LSIG and checks if the app id stored in the passed-in NFD name's
# registry-contract local state matches the passed Nfd App ID.
# ie: patrick.algo -> check registry contract discovery mechanism -> read app id.. does it match.
@Subroutine(TealType.uint64)
def is_nfd_id_authentic(nfd_name, nfd_app_id):
    lsigByteCode = ScratchVar(TealType.bytes)
    nameBytes = ScratchVar(TealType.bytes)
    progHash = ScratchVar(TealType.bytes)

    localGetMv = App.localGetEx(progHash.load(), Tmpl.Int("TMPL_NFD_RC_ID"), REGISTRY_KEY_APPID)
    return Seq(
        nameBytes.store(Concat(Bytes("name/"), nfd_name)),

        lsigByteCode.store(Concat(Bytes("base16", "0x052001018008010203040506"),
                                  Bytes("base16", "0x070817350031183400123110"),
                                  Bytes("base16", "0x810612103119221231198100"),
                                  Bytes("base16", "0x1211104000010022432601"))),
        # Now replace bytes 6-13 w/ NFD's registry contract id
        lsigByteCode.store(Replace(lsigByteCode.load(), Int(6), Itob(Tmpl.Int("TMPL_NFD_RC_ID")))),
        # then concat {length}name/{nfd_name} - uvar int (just last byte in BE value) - then bytes of string
        lsigByteCode.store(
            Concat(lsigByteCode.load(), encode_uvarint(Len(nameBytes.load())), nameBytes.load())),
        # we can now hash these bytes to get our LSIG address
        progHash.store(Sha512_256(Concat(Bytes("Program"), lsigByteCode.load()))),
        localGetMv,
        Assert(localGetMv.hasValue(),
               comment="lsig has to have i.appid localstate"),
        Return(Btoi(localGetMv.value()) == nfd_app_id))


```

See [Registry Application IDs](/reference/on-chain-reference/registry-application-ids.md)for the correct registry ID to substitute in the TMPL\_NFD\_RC\_ID parameter.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-docs.nf.domains/reference/on-chain-reference/name-and-address-lookup/v1-resolution-example-go/example-pyteal-name-id-validity-check.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
