Nanowires and nanotubes carry charge and excitons efficiently, and are ther
efore potentially ideal building blocks for nanoscale electronics and optoe
lectronics(1,2). Carbon nanotubes have already been exploited in devices su
ch as field-effect(3,4) and single-electron (5,6) transistors, but the prac
tical utility of nanotube components for building electronic circuits is li
mited, as it is not yet possible to selectively grow semiconducting or meta
llic nanotubes(7,8). Here we report the assembly of functional nanoscale de
vices from indium phosphide nanowires, the electrical properties of which a
re controlled by selective doping. Gate-voltage-dependent transport measure
ments demonstrate that the nanowires can be predictably synthesized as eith
er n- or p-type. These doped nanowires function as nanoscale field-effect t
ransistors, and can be assembled into crossed-wire p-n junctions that exhib
it rectifying behaviour. Significantly, the p-n junctions emit light strong
ly and are perhaps the smallest light-emitting diodes that have yet been ma
de. Finally, we show that electric-field-directed assembly can be used to c
reate highly integrated device arrays from nanowire building blocks.