Skip to content

Instantly share code, notes, and snippets.

@FlacoJones
Created January 21, 2022 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlacoJones/1b15cb59cfc72065b75617ecab8af339 to your computer and use it in GitHub Desktop.
Save FlacoJones/1b15cb59cfc72065b75617ecab8af339 to your computer and use it in GitHub Desktop.
index.js
// Import dependencies available in the autotask environment
const { DefenderRelayProvider, DefenderRelaySigner } = require('defender-relay-client/lib/ethers');
const { ethers } = require('ethers');
const OPENQ_ABI = [{"inputs":[{"internalType":"string","name":"_id","type":"string"},{"internalType":"address","name":"_payoutAddress","type":"address"}],"name":"claimBounty","outputs":[],"stateMutability":"nonpayable","type":"function"}]
const OPENQ_ADDRESS = `0x5fB848E68Ed73D38195c9970Ac19a627f2fbFaf1`;
// Entrypoint for the Autotask
exports.handler = async function(event) {
const { issueId, payoutAddress } = event.request.body;
const provider = new DefenderRelayProvider(event);
const signer = new DefenderRelaySigner(event, provider, { speed: 'fastest' });
const openQ = new ethers.Contract(OPENQ_ADDRESS, OPENQ_ABI, signer);
const txn = await openQ.claimBounty(issueId, payoutAddress);
console.log(`Called execute in ${txn.hash}`);
return { tx: tx.hash };
}
// To run locally (this code will not be executed in Autotasks)
if (require.main === module) {
require('dotenv').config();
const { API_KEY: apiKey, API_SECRET: apiSecret } = process.env;
exports.handler({ apiKey, apiSecret })
.then(() => process.exit(0))
.catch(error => { console.error(error); process.exit(1); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment