I suggest you to disable automatic triggers inspect / run them yourself.
In order to disabled the automatic execution of a plugin trigger you need to set the option
object when you call the endpoint.
For example:
const createBuyOrder = async () => {
try {
const options = { disableTriggers: true }; // Option object
const result = await Moralis.Plugins.opensea.createBuyOrder(
{
network: 'testnet',
tokenAddress: '0xdf524d78dc60e185ba674eb64d04a8a45d228fba',
tokenId: '421',
amount: 0.0005,
userAddress: web3Account.address,
tokenType: 'ERC1155',
paymentTokenAddress: '0xc778417e063141139fce010982780140aa0cd5ab',
gas: 50000,
},
options // Option is passed as 2nd parameter when your call a plugin endpoint
);
console.log('Got parameters to create a new buy order::\n', result);
} catch (error) {
new Error(error.message || error);
}
};
If you check the console, you will see that the result from the plugin is logged.
This is what the plugin sends back to the Moralis SDK.
Check the trigger array at position 0.
You see a web3Transaction
trigger.
Now you can take code from the SDK and, after changing few thing, you can use your own account (instead of metamask) to run the triggers.
Moralis SDK: https://github.com/MoralisWeb3/Moralis-JS-SDK
I have done for you the web3Transaction
trigger. You can play with the SDK to find out how to run new triggers such as web3Sign
.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
</head>
<body>
<script>
const MORALIS_APP_ID = '';
const MORALIS_SERVER_URL = '';
const PK = '';
const MORALIS_SPEEDY_NODE = '';
// Connect to Moralis server
const web3 = new Web3(MORALIS_SPEEDY_NODE);
let web3Account;
const init = async () => {
await Moralis.start({ serverUrl: MORALIS_SERVER_URL, appId: MORALIS_APP_ID });
await Moralis.enable();
await Moralis.initPlugins();
web3Account = await web3.eth.accounts.wallet.add(PK);
createBuyOrder();
};
const createBuyOrder = async () => {
try {
const options = {
disableTriggers: true,
};
const [user] = await web3.eth.getAccounts();
const result = await Moralis.Plugins.opensea.createBuyOrder(
{
network: 'testnet',
tokenAddress: '0xdf524d78dc60e185ba674eb64d04a8a45d228fba',
tokenId: '421',
amount: 0.0005,
userAddress: web3Account.address,
tokenType: 'ERC1155',
paymentTokenAddress: '0xc778417e063141139fce010982780140aa0cd5ab',
gas: 50000,
},
options
);
console.log('Got parameters to create a new buy order::\n', result);
handleTriggers(result.triggers, result);
} catch (error) {
new Error(error.message || error);
}
};
const ERROR_WEB3_MISSING =
'Missing web3 instance, make sure to call Moralis.enableWeb3() or Moralis.authenticate()';
const handleTriggers = async (triggersArray, payload) => {
function ensureWeb3IsInstalled() {
return web3 ? true : false;
}
if (!triggersArray) return;
let response;
for (let i = 0; i < triggersArray.length; i++) {
switch (triggersArray[i]?.name) {
case 'web3Transaction':
if (!ensureWeb3IsInstalled()) throw new Error(ERROR_WEB3_MISSING);
// Trigger a web3 transaction (await)
if (triggersArray[i]?.shouldAwait === true)
response = await web3.eth.sendTransaction(triggersArray[i]?.data);
// Trigger a web3 transaction (does NOT await)
if (triggersArray[i]?.shouldAwait === false) response = web3.eth.sendTransaction(triggersArray[i]?.data);
// Return payload and response
if (triggersArray[i]?.shouldReturnPayload === true) return { payload: payload, response: response };
// Only return response
if (triggersArray[i]?.shouldReturnResponse === true) return response;
break;
default:
throw new Error(`Unknown trigger: "${triggersArray[i]?.name}"`);
}
}
};
init();
</script>
</body>
</html>