diff --git a/examples/list-contracts/index.js b/examples/list-contracts/index.js new file mode 100644 index 00000000..efb90752 --- /dev/null +++ b/examples/list-contracts/index.js @@ -0,0 +1,22 @@ +require('dotenv').config(); + +const { Defender } = require('@openzeppelin/defender-sdk'); + +async function main() { + const creds = { apiKey: process.env.API_KEY, apiSecret: process.env.API_SECRET }; + const client = new Defender(creds); + + const contracts = await client.proposal.listContracts({ includeAbi: false }); + + if (contracts.length > 0) { + const firstContractId = `${contracts[0].network}-${contracts[0].address}`; + const first = await client.proposal.getContract(firstContractId); + console.log('first contract:', first); + } + + console.log(contracts); +} + +if (require.main === module) { + main().catch(console.error); +} diff --git a/examples/list-contracts/package.json b/examples/list-contracts/package.json new file mode 100644 index 00000000..2249463c --- /dev/null +++ b/examples/list-contracts/package.json @@ -0,0 +1,15 @@ +{ + "name": "@openzeppelin/defender-sdk-example-list-contracts", + "version": "1.7.0", + "private": true, + "main": "index.js", + "author": "Nami Shah ", + "license": "MIT", + "scripts": { + "start": "node index.js" + }, + "dependencies": { + "@openzeppelin/defender-sdk": "1.7.0", + "dotenv": "^16.3.1" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3134d122..819c3afc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -181,6 +181,15 @@ importers: specifier: ^16.3.1 version: 16.3.1 + examples/list-contracts: + dependencies: + '@openzeppelin/defender-sdk': + specifier: 1.7.0 + version: link:../../packages/defender-sdk + dotenv: + specifier: ^16.3.1 + version: 16.3.1 + examples/list-networks: dependencies: '@openzeppelin/defender-sdk':