I’m trying to set up a Job on my server that will send a transaction from a specific account to my smart contract in response to a particular event. I have an NFT auction contract that requires a public function to be called after an auction ends to trigger the finalization of the auction.
I’ve set up an account that I want to use as a sort of relayer for this: I make sure this account is funded, store it’s private key on the server and use that to create a signer to send the transaction. Here’s some code:
import ethers from 'ethers';
Moralis.Cloud.job('settleAuction', async (request) => {
const web3 = Moralis.web3;
// Get a provider somehow. Tried the following:
const provider1 = Moralis.enableWeb3();
const provider1 = Moralis.provider;
const provider2 = Moralis.web3;
const provider3 = Moralis.web3.provider;
// etc.
// create signer using private key
const signer = new ethers.Wallet(signerPrivateKey, provider);
const auctionHouse = new ethers.Contract(auctionHouseAddress, abi, signer);
// ... send transaction, etc.
}
Note: importing ethers instead of using const ethers = Moralis.web3Library
to have access to ethers.wallet
Anyone have any other ideas on how I can get the provider I need or an alternative way of creating a new signer from a provided private key in Moralis?