0
votes

I am trying to use Coinbase's API to get my wallet info to eventually make transactions using Python. Below is the 2 lines of code that i have written:

from coinbase.wallet.client import Client
client = Client(api_key, api_secret)

After running, I get the error--> 'NameError: name 'api_key' is not defined'. I know that I am supposed to set up an API Key and API Secret via Coinbase (which I have done already) and even put them both in the 'Client' parenthesis. Cany anyone tell me what I am doing wrong or guide me to successfully use my Coinbase API in Python?

2

2 Answers

1
votes

Make sure you initialize both vars before creating the client

from coinbase.wallet.client import Client
api_key = 'my api key here'
api_secret = 'my api secret'
client = Client(api_key, api_secret)

The error specifically tells you that api_key is not defined

1
votes

The error is self explanatory, your variable api_key and api_secret are undefined, thus the NameError exception.

  1. What you can is replace api_key by hardcoding your key and secret provided by Coinbase (it should be in the form of a long randomly generated string)

  2. Verify that you can indeed perform an API call on Coinbase

  3. Now, remove the hardcoded version and use environment variables instead (this will prevent you from publishing your keys to public repositories by mistakes) How to use environment variables for API keys