Start at the town gate and talk to Copper. Choose the "friend code" option from the menu.
Make sure your console can actually reach the internet first. Once it is connected, Copper will give you the code.