Defender SDK and API
Defender SDK (Formerly defender-client packages) is a node package that allows developers to interact with Defender programatically using Javascript/Typescript.
See sdk repository or SDK and API documentation for more detailed information.
Installation
You can install the whole package using NPM or any of your favorite package managers
npm install @openzeppelin/defender-sdk
or you can install single subpackages
npm install @openzeppelin/defender-sdk-deploy-client
For more information about setup, examples and usage, please visit Defender SDK README file in Github. |
API Keys
In order to operate your Defender account using the SDK or API, Defender requires API keys and secrets generated in the dashboard to authenticate requests.
When creating API keys, you can also specify the expiration in days, hours and minutes.
Defender notifies 3 days before and at expiration time about the API keys expiration.
Once the key is expired, any request sent to Defender API will throw API Key is either expired or invalid error.
|
Relayer API Keys
Relayers API Keys are generated in Relayer details page, and are exclusively used for managing the signer operations for that Relayer, e.g. send or query transactions, get the nonce or sign data.
const creds = {
relayerApiKey: <RELAYER_API_KEY>,
relayerApiSecret: <RELAYER_API_SECRET>,
};
const client = new Defender(creds);
const txResponse = await client.relaySigner.sendTransaction({
to: '0x179810822f56b0e79469189741a3fa5f2f9a7631',
value: 1,
speed: 'fast',
gasLimit: '21000',
});
Only client.relaySigner package is available when authenticating using relayerApiKey and relayerApiSecret .
|
Admin API Keys
Admin API Keys are generated in Manage → API Keys, and they are used to operate all other resources in Defender, including relayers CRUD operations.
const creds = {
apiKey: <API_KEY>,
apiSecret: <API_SECRET>,
};
const client = new Defender(creds);
const proposals = await client.proposal.list({
limit: 10,
next: undefined,
});