Created
June 15, 2021 10:50
-
-
Save gotjoshua/86a4da9ec175067eed162d7d177e9d28 to your computer and use it in GitHub Desktop.
moralis real time sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Moralis.Cloud.beforeConsume('Shipped', (event) => { | |
if (!event.confirmed) return false | |
delete event.address | |
delete event.confirmed | |
delete event.block_hash | |
log(`beforeConsume - ${event}`) | |
return true | |
}) | |
Moralis.Cloud.afterSave('Shipped', async (request) => { | |
const config = await Moralis.Config.get({ useMasterKey: true }) | |
const CHAIN_ID = config.get('CHAIN_ID') | |
const VERITAS_CONTRACT = config.get('VERITAS_CONTRACT') | |
const VERITAS_ABI = JSON.parse(config.get('VERITAS_ABI')) | |
const web3 = Moralis.web3ByChain(CHAIN_ID) | |
const txHash = request.object.get('transaction_hash') | |
const tokenId = request.object.get('tokenId') | |
const txObj = await web3.eth.getTransaction(txHash) | |
const shipper = txObj.from | |
const etherscan = `${ETHERSCAN_RINKEBY}${txHash}` | |
const contract = new web3.eth.Contract(VERITAS_ABI, VERITAS_CONTRACT) | |
const balance = await contract.methods.balanceOf(shipper).call() | |
const msg = `Shipped: #${tokenId}\naddress: ${formatAddressShort(shipper)}\nholding: ${balance} VERITAS total\n[etherscan link](${etherscan})\n==========` | |
log(msg) | |
await sendToDiscord(DISCORD_CONTRACT_INTERACTIONS, msg) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment