Hi everyone,
I'm trying to run an autotask using webhook. The idea is to pass two values "ipfsCid" and "username" inside the body of the HTTP request that will be passed dynamically inside the smart contract call.
This is the call for the webhook
--header 'Content-Type: application/json' \
--data-raw '{
"ipfsCid": "QmfELgWd5V261TCSxKqferBAfoXVvwugKY59mntFMifoLT",
"bytes32UserName": "0x656e7269636f0000000000000000000000000000000000000000000000000000"
}'
While this is the code of the autotask
const { DefenderRelaySigner, DefenderRelayProvider } = require('defender-relay-client/lib/ethers');
const ethers = require('ethers');
exports.handler = async function(event) {
const provider = new DefenderRelayProvider(event);
const signer = new DefenderRelaySigner(event, provider);
// Use provider and signer for querying or sending txs from ethers, for example...
let registry_ADDR = "0x2cFB3A82fAff819dB7fEBBCD75Bef6200a55dce4"
let REGISTRY_ABI = [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "bytes32",
"name": "domain",
"type": "bytes32"
},
{
"indexed": true,
"internalType": "string",
"name": "ownerData",
"type": "string"
}
],
"name": "NewDomain",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "domain",
"type": "bytes32"
},
{
"internalType": "string",
"name": "ownerData",
"type": "string"
}
],
"name": "setDomain",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
const {
body, // Object with JSON-parsed POST body
headers, // Object with key-values from HTTP headers
queryParameters, // Object with key-values from query parameters
} = event.request;
var ipfsCid = JSON.parse(body).ipfsCid;
var bytes32UserName = JSON.parse(body).bytes32UserName;
const contract = new ethers.Contract(registry_ADDR, REGISTRY_ABI, signer);
await contract.setDomain(bytes32UserName, ipfsCid)
}
When executing this post request I get an error message
'Unexpected token Q in JSON at position 0' as I'm not able to parse the body of the request correctly. Do you have any idea how to solve that?