The Stanley’s bio-pharma operation is just one example of the ways science and tech are transforming every aspect of the industry—from growing to harvesting to packaging to retailing to consuming—as this black (and gray) market emerges into the sunlight of legitimate commerce.

Start with indoor farms, which are massively energy-intensive. Their high-pressure sodium lights, which themselves require large amounts of electricity, can send temperatures soaring. Yet marijuana plants need to stay cool and dry. Traditionally, growers have handled this dilemma by using electricity-gulping HVAC compressors. Colorado company Surna saw opportunity here. It has introduced an energy-efficient climate-control system that uses chilled water. The system pipes a circuit of cooling water through the grow and can even extract water directly from the indoor air to regulate humidity. “This plant is from Afghanistan. It wants to be on a windy hill in semi-arid conditions,” says Surna CEO Tom Bollich. “That’s one thing we can do that traditional HVAC can’t—we can give you 40 percent humidity and 75 degrees.” If Bollich’s name is familiar, it could be that you know him from his previous gig: CTO of Zynga. “I moved on from that, did several startups and moved around, and started looking into the cannabis industry,” he says. “It was the next gold rush, honestly.”

Ready to make a purchase? Silicon Valley has you covered there, too.

Earlier this year, Bollich bought the company that makes the water-cooling tech. But he says the real path to market domination will come when he combines the technology with a software system designed to control all that hardware. “I would rather do a combination of hardware and software, because it is so much more difficult,” he says. “The barrier to entry with that two-punch combo is so high.”

While Bollich is cooling down indoor farms, others are working to prevent them from heating up to begin with. A new generation of LED lights offers a more energy-efficient, cooler way to grow marijuana. The big question is whether these bulbs are as effective as traditional lighting.

In an attempt to answer that, the San Francisco Patient and Resource Center’s (SPARC) marijuana nursery is running A/B tests with LED lights from a company called LumiGrow. Two indoor tents each house identical strains of marijuana, called Green Dragon, which were cloned from the same mother. One tent is outfitted with LED lights; the other has high-pressure sodium bulbs. The preliminary results suggest that the LED illumination may be superior. The LED-grown plants are much shorter due to the cooler temperature. And shorter plants are preferable, because they devote more energy to flowering than growing upward. And unlike the tent using conventional high-pressure sodium lamps, the LED tent requires no air-conditioning.

Before installing this new lighting in its main grow, SPARC is trying to determine if the LED system can produce yields equivalent to conventional high-pressure sodium lights. After all, the LumiGrow LEDs costs about seven times more than the conventional lights. But they save so much energy once installed, says SPARC founder Erich Pearson, that he expects to recoup costs in about 14 months if yields are similar.

There’s another aspect of LED that also has the potential to be transformational. Traditionally growers keep young plants basking in light 24 hours a day and then switch to a schedule that gives them 12 hours of light and 12 hours of darkness as they mature. The darkness slows the plants’ growth, but that simulated night is necessary to trigger the all-important flowering of buds.

SPARC’s production director, Robby Flannery, who holds a PhD in plant biology, says he may have figured out a way for his plants to have their buds and gorge on light too. To a plant, the absence of light in the red spectrum signals night. So by eliminating red light 12 hours a day while continuing to shine blue light, SPARC should be able to create plants that still produce buds while constantly absorbing light. “You can keep driving photosynthesis and trick them into thinking it’s nighttime,” he says. Flannery is setting up the A/B test now and plans to publish an academic paper in conjunction with the University of California–Davis later this year.

The next stage of the supply chain, harvesting and drying, is also undergoing an infusion of technology and innovation. In the process of being harvested and dried, marijuana plants are often moved around to various rooms in grow operations–one room for drying, for example, and another for trimming. Growers need to track this process precisely, both to monitor inventory and for legal reasons. That’s where tools built by the likes of Agrisoft come in. The Kansas City, Missourri, company (tagline: Seed to Sale) makes gear that can use both fingerprint scanners and RFID sensors to follow plants around a grow and even out to dispensaries. Right now, Realm of Caring is using handheld RFID scanners to do all this tracking, but it wants to automate the process even further. “We’re hoping to purchase sensors for different parts of the grow that will detect tags as you move plants from room to room,” says Hannah Root, a premed graduate who manages the day-to-day grow operations.

Before plants can head out to a dispensary, they have to be trimmed to make them more aesthetically appealing and easier to smoke. Trimmers sit all day long at a table, cutting away leaves and stems by hand. You can buy a $100,000 automatic trimmer to do this job, but that’s cost-prohibitive. Typically, you’re talking about pruning shears running on elbow grease, which can lead to repetitive stress injuries. “When people are moving into OSHA-standards situations, this matters,” explains Troy Dayton, co-founder and CEO of the ArcView group, an investor network that’s bankrolling cannabis ventures. “In the underground economy, who cares? Hire the next person. But in the aboveground economy, we have rules around that.”

One of Dayton’s bets is on TurboTrimmerz, a prototype scissor that works by pressing a touchpad rather than gripping the handles of the shears. The idea is that it will help keep workers from hurting their hands as frequently, while also speeding up the amount of time it takes to trim a harvest. ( You can also find them on Angel List, naturally.)

The most overarching challenge many pot farmers face is inventory management. Growers in Colorado are required to track all parts of all plants (even the compost) from seed to sale. They have to be able to show that all parts of all the plants they’ve handled have moved through legal channels and that no buds or cuttings (which could be used to clone plants) were passed on to the black market. Yet because marijuana is sold by weight and becomes lighter due to evaporation (even after it has been dried), keeping precise track of inventory poses a real challenge. “Imagine if, after a diamond sat on the shelf for some length of time, it lost enough weight to affect its price in significant ways,” Dayton says.