Adding a package to defender autotask node runtime environment

:computer: Environment

:memo:Details

:1234: Code to reproduce

hello, I am trying to build a crypto offRamp and I am using auto tasks to trigger payments when certain conditions are met.
here is the link to the repository

It works fine on the test environment and would like to push the code to defender however, flutterwave-node-v3 is not preinstalled, and trying to use rollup is getting really challenging.

here is my autotask code.

const ethers = require("ethers")
const Flutterwave = require("flutterwave-node-v3")
const {
  DefenderRelaySigner,
  DefenderRelayProvider,
} = require("defender-relay-client/lib/ethers")

const { ForwarderAbi } = require("../../src/forwarder")
const ForwarderAddress = require("../../deployCashout.json").MinimalForwarder
const { FLW_PUBLIC_KEY: publicKey, FLW_SECRET_KEY: secretKey } = process.env
const flw = new Flutterwave(publicKey, secretKey)


async function relay(forwarder, request, signature, params, whitelist) {
  // Decide if we want to relay this request based on a whitelist
  const accepts = !whitelist || whitelist.includes(request.to)
  if (!accepts) throw new Error(`Rejected request to ${request.to}`)

  // Validate request on the forwarder contract
  const valid = await forwarder.verify(request, signature)
  if (!valid) throw new Error(`Invalid request`)

  // Send meta-tx through relayer to the forwarder contract
  const gasLimit = (parseInt(request.gas) + 50000).toString()
  const tx = await forwarder.execute(request, signature, { gasLimit })
  const reciept = await tx.wait(10)
  // include logic to query the cashout contract matching the exact transaction hash for events //emitted or for the ERC20 transfers.
//make fiat payment upon confirmation
  try {
    const { data } = await flw.Transfer.initiate(params)
    console.log(data)
  } catch (error) {
    console.log(error)
  }
  console.log(reciept)
  return reciept
}

async function handler(event) {
  // Parse webhook payload
  if (!event.request || !event.request.body) throw new Error(`Missing payload`)
  const { request, signature, params } = event.request.body
  console.log(`Relaying`, request, signature)

  // Initialize Relayer provider and signer, and forwarder contract
  const credentials = { ...event }
  const provider = new DefenderRelayProvider(credentials)
  const signer = new DefenderRelaySigner(credentials, provider, {
    speed: "fast",
  })
  const forwarder = new ethers.Contract(ForwarderAddress, ForwarderAbi, signer)

  // Relay transaction!
  const tx = await relay(forwarder, request, signature, params)
  console.log(`Sent meta-tx: ${tx.confirmations}`)
  return { txHash: tx.confirmations }
}

module.exports = {
  handler,
  relay,
}

looking forward to your assistance with this and any more questions you may have...

@eliashezron

Hi

Seems like rollup is complaining about using private keywords in flutterwave-node-v3 package.
If possible one option is to change those issues in that package.
Second option could be to try to use some other bundler like webpack.

Best,
Zeljko

@zeljko I was able to successfully do it with webpack thanks to @spalladino defender auto task example here

1 Like