I need some help, please. I have an Autotask with a relay. I am calling it with a webhook from my app. It safeMints an NFT with URI Storage. I send the URI and Recipient in the JSON body of my fetch.
How do I access the payload (URI and Recipient) in my Autotask? I have tried a few different ways:
To get the json body..
const formData = JSON.parse(params.request.body)
or
const formData = JSON.parse(event.request.body)
Then
const URI = formdata.uri;
const RECIPIENT = formdata.recipient;
Errors: request or event is not defined
By the way, If I hard code the uri and the recipient in the Autotask it succeeds.
Here’s my Autotask code:
const ABI = [`function safeMint(address to, string uri) public`];
const formdata = JSON.parse(params.request.body);
const URI = formdata.uri;
const RECIPIENT = formdata.recipient;
const ADDRESS = "0xb56C22a246F39ac92fAFae8EAA82996f00ef5F19";
const { ethers } = require("ethers");
const {
DefenderRelaySigner,
DefenderRelayProvider,
} = require("defender-relay-client/lib/ethers");
/** Mint an NFT for the recipient */
async function main(signer, recipient) {
const nft = new ethers.Contract(ADDRESS, ABI, signer);
const tx = await nft.safeMint(recipient, URI);
console.log(`Minted an NFT for ${recipient} in ${tx.hash}`);
}
exports.handler = async function (params) {
const provider = new DefenderRelayProvider(params);
const signer = new DefenderRelaySigner(params, provider, { speed: "fast" });
console.log(`Using relayer ${await signer.getAddress()}`);
await main(signer, RECIPIENT);
};