How to get real API_KEY and API_SECRET for Relayer?

I have setup Defender account and setup a relayer for usage with Rinkeby network.

Upon creation I noted:

  • Address
  • API Key
  • Private Key

Then I followed Documentation and installed defender-relay-client into my application and tried to execute some code.

Buit I need API_KEY and API_SECRET:

import { RelayClient } from 'defender-relay-client';
const relayClient = new RelayClient({ apiKey: API_KEY, apiSecret: API_SECRET });

My issue:

  1. API_SECRET was never told and can't get retrieved in Defender
  2. API_KEY is not known to defender, I get an error message:

Failed to get a token for the API key xxxxxxxxxx: User does not exist.

:computer: Environment

"defender-relay-client": "^1.30.0",

:memo:Details

As written above.

:1234: Code to reproduce

Provided above.

The key and secret for the defender-client packages refers to the Team API key/secret. You can generate a new one by selecting the menu at the top right in the Defender web interface --> Team API Keys. You can assign whatever access rights are necessary on the next screen.

This key would then be saved in your .env file and referred to when instantiating one of the defender-client packages (such as RelayClient).

If you're wanting to send transactions directly using the relayer (such as when using a Relayer to deploy contracts), you can create a new key for the relayer with await relayClient.createKey('[RELAYER ID]');

It's important to note that this key should be kept secure as well.

1 Like

Thank you @slw.eth.

I think there is still something big missing.

This is my code taking from README:

    const credentials = { apiKey: API_KEY, apiSecret: API_SECRET };
    const provider = new DefenderRelayProvider(credentials);
    const signer = new DefenderRelaySigner(credentials, provider, { speed: 'fast' });

    console.log("Signer", await signer.getAddress())

On signer.getAddress I get the error message:

Code: -1; Message: Failed to get a token for the API key xxxxxx: User does not exist

I have created the Team-APIKEY- and API-Secret which is used in credentials.
I have setup a relayer in Defender also, but both seems not to be related or at least I see nothing to add a User to one of both things.

What I wanted to do actually is:

    const contract = new ethers.Contract(contractAddress, abi, signer);
    tx = await contract.functions.safeTransferFrom(from, to, tokenId, amount, .... });

But everything fails with "user does not exist".

I think I have now understood your answer better.

I had to use createKey for my relayer in order to obtain API_KEY and SecretKEY that I could use then for my other actions using DefenderRelayProvider.

Thank you @slw.eth

1 Like