Factual question about Deadwood SD

In the new TV series, much of the frontier town’s infamy derives from the fact that when it was first founded it was literally “outside the law”: it was illegally built on Dakota land that the Federal government had agreed by treaty not to annex. Obviously this must have eventually become a dead letter. So how long was Deadwood “lawless”, and when did it finally come under US jurisdiction?

You might want to get this tossed to CAFE SOCIETY. There have been long threads posted after every episode. Many cites to the real Deadwood.