Skip to content

Commit

Permalink
Create NexusCrossChainMessageContract.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jul 27, 2024
1 parent 7e31c8f commit 9a6951c
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Web3 = require('web3');
const Ethers = require('ethers');

class NexusCrossChainMessageContract {
constructor(nexusCrossChainMessageContractAddress, providerUrl) {
this.nexusCrossChainMessageContractAddress = nexusCrossChainMessageContractAddress;
this.web3 = new Web3(new Web3.providers.HttpProvider(providerUrl));
this.ethersProvider = new Ethers.providers.JsonRpcProvider(providerUrl);
}

async sendMessage(messageId, message) {
const txCount = await this.web3.eth.getTransactionCount(this.nexusCrossChainMessageContractAddress);
const tx = {
from: this.nexusCrossChainMessageContractAddress,
to: this.nexusCrossChainMessageContractAddress,
value: '0',
gas: '20000',
gasPrice: '20',
nonce: txCount,
data: `0x${messageId.toString(16)}${message}`
};
const signedTx = await this.ethersProvider.signTransaction(tx, '0x1234567890abcdef');
await this.ethersProvider.sendTransaction(signedTx);
}

async getMessage(messageId) {
return this.web3.eth.call({
to: this.nexusCrossChainMessageContractAddress,
data: `0x${messageId.toString(16)}`
});
}
}

module.exports = NexusCrossChainMessageContract;

0 comments on commit 9a6951c

Please sign in to comment.