Skip to content

Commit

Permalink
add list contracts example (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
MCarlomagno authored Jan 10, 2024
1 parent 54712c6 commit fe24bdb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/list-contracts/index.js
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 15 additions & 0 deletions examples/list-contracts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@openzeppelin/defender-sdk-example-list-contracts",
"version": "1.7.0",
"private": true,
"main": "index.js",
"author": "Nami Shah <[email protected]>",
"license": "MIT",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@openzeppelin/defender-sdk": "1.7.0",
"dotenv": "^16.3.1"
}
}
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fe24bdb

Please sign in to comment.