Surface transfer doping can mediate both colloidal stability and self-assembly of nanodiamonds.