Bridge dapp not working

I’m using a simple variant of the moralis bridge.

Moralis.Cloud.afterSave("EthTokenTransfers", (request) => {
18    const data = JSON.parse(JSON.stringify(request.object, ["token_address", "to_address", "from_address","transaction_hash","value", "confirmed"]));
19    logger.info(data);
20    if (data["token_address"] == mainToken_address.toLocaleLowerCase() && data["to_address"] == MainBridge_address.toLocaleLowerCase() && !data["confirmed"]) {
21        const txlock = processBridgeRequestLock(data);
22        const txbridge = processBridgeRequestBridge(data);
23    }
24    else{
25        logger.info("transaction not related to bridge");
26    }
27    async function processBridgeRequestLock(data) {
28        logger.info("bridging starting locking tokens");
29        const functionCall = MainBridge.methods.lockTokens(data["from_address"],data["value"],data["transaction_hash"]).encodeABI();
30        const gatewayNonce = web3Main.eth.getTransactionCount(gateway_address);
31        const transactionBody = {
32            to: MainBridge_address,
33            nonce:gatewayNonce,
34            data:functionCall,
35            gas:400000,
36            gasPrice:web3Main.utils.toWei("100", "gwei")
37        }
38        signedTransaction = await web3Main.eth.accounts.signTransaction(transactionBody,gatewayKey);
39        logger.info(signedTransaction.transactionHash);
40        fulfillTx = await web3Main.eth.sendSignedTransaction(signedTransaction.rawTransaction);
41        logger.info("fulfillTx: " + JSON.stringify(fulfillTx));
42    }
43    async function processBridgeRequestBridge(data) {
44        logger.info("bridging tokens");
45        const functionCall = SideBridge.methods.bridgeTokens(data["from_address"],data["value"],data["transaction_hash"]).encodeABI();
46        const gatewayNonce = web3Side.eth.getTransactionCount(gateway_address);
47        const transactionBody = {
48            to: SideBridge_address,
49              nonce:gatewayNonce,
50              data:functionCall,
51              gas:400000,
52              gasPrice:web3Side.utils.toWei("15", "gwei")
53        }
54        signedTransaction = await web3Side.eth.accounts.signTransaction(transactionBody,gatewayKey);
55        logger.info(signedTransaction.transactionHash);
56        fulfillTx = await web3Side.eth.sendSignedTransaction(signedTransaction.rawTransaction);
57        logger.info("fulfillTx: " + JSON.stringify(fulfillTx))
58        return fulfillTx;
59    }
60});
61
62
63Moralis.Cloud.afterSave("BscTokenTransfers", (request) => {
64    const data = JSON.parse(JSON.stringify(request.object, ["token_address", "to_address", "from_address","transaction_hash","value", "confirmed"]));
65    logger.info(data);
66    if (data["token_address"] == childToken_address.toLocaleLowerCase() && data["to_address"] == SideBridge_address.toLocaleLowerCase() && !data["confirmed"]) {
67        const txlock = processReturnBurn(data);
68        const txbridge = processReturnUnlock(data);
69    }
70    else{
71        logger.info("transaction not related to bridge");
72    }
73    async function processReturnBurn(data) {
74        logger.info("returning tokens burning");
75        const functionCall = SideBridge.methods.returnTokens(data["from_address"],data["value"],data["transaction_hash"]).encodeABI();
76        const gatewayNonce = web3Side.eth.getTransactionCount(gateway_address);
77        const transactionBody = {
78            to: SideBridge_address,
79              nonce:gatewayNonce,
80              data:functionCall,
81              gas:400000,
82              gasPrice:web3Side.utils.toWei("15", "gwei")
83        }
84        signedTransaction = await web3Side.eth.accounts.signTransaction(transactionBody,gatewayKey);
85        logger.info(signedTransaction.transactionHash);
86        fulfillTx = await web3Side.eth.sendSignedTransaction(signedTransaction.rawTransaction);
87        logger.info("fulfillTx: " + JSON.stringify(fulfillTx))
88        return fulfillTx;
89    }
90    async function processReturnUnlock(data) {
91        logger.info("returning starting unlocking tokens");
92        const functionCall = MainBridge.methods.unlockTokens(data["from_address"],data["value"],data["transaction_hash"]).encodeABI();
93        const gatewayNonce = web3Main.eth.getTransactionCount(gateway_address);
94        const transactionBody = {
95            to: MainBridge_address,
96              nonce:gatewayNonce,
97              data:functionCall,
98              gas:400000,
99              gasPrice:web3Main.utils.toWei("200", "gwei")
100        }
101        signedTransaction = await web3Main.eth.accounts.signTransaction(transactionBody,gatewayKey);
102        logger.info(signedTransaction.transactionHash);
103        fulfillTx = await web3Main.eth.sendSignedTransaction(signedTransaction.rawTransaction);
104        logger.info("fulfillTx: " + JSON.stringify(fulfillTx));
105    }
106});

The logger is reading the transactions then it appears to be trying to do something but it’s not actually executing them.

  1. 2022-09-06T15:10:40.720Z - transaction not related to bridge
  2. 2022-09-06T15:10:40.720Z - transaction not related to bridge
  3. 2022-09-06T15:10:40.720Z - undefined
  4. 2022-09-06T15:10:38.898Z - transaction not related to bridge
  5. 2022-09-06T15:10:38.897Z - undefined
  6. 2022-09-06T15:10:37.236Z - transaction not related to bridge
  7. 2022-09-06T15:10:37.234Z - undefined
  8. 2022-09-06T15:09:43.848Z - returning starting unlocking tokens
  9. 2022-09-06T15:09:43.827Z - returning tokens burning
  10. 2022-09-06T15:09:43.826Z - undefined

https://ssehjnedi8yt.usemoralis.com:2053/server

it looks like it doesn’t enter in that first if?

try to use logger.info(JSON.stringify(data)) here

I’ll give it a try. It’s so weird because I didn’t change anything and it just stopped working for some reason.

you have your own RPC node url in code, right?

We don’t is it because the speedy nodes are gone?

const web3Main = Moralis.web3ByChain("0x1"); // Ethereum Mainnet
const web3Side = Moralis.web3ByChain("0x38"); // BSC Mainnet

this doesn’t work now, you’ll have to use a custom RPC url and initialise a web3 instance

That would explain the problem. What’s the code to initialize a web3 instance?

https://v1docs.moralis.io/moralis-dapp/cloud-code/cloud-functions#example-of-how-to-use-a-custom-rpc-url

Just so I’m tracking down the right path.

// insert eth node here
const web3main = new Moralis.Web3(
new Moralis.Web3.providers.HttpProvider(
“SPEEDY NODE URL”
)
);

//insert bsc node here
const web3side = new Moralis.Web3(
new Moralis.Web3.providers.HttpProvider(
“SPEEDY NODE URL”
)
);

I use this to replace the code I sent above, correct?
Sorry for the ignorance on this.

yet looks like that is what you should do, you will need RPC urls there to use