Skip to content

Commit 07d172e

Browse files
author
David Adamyan
committed
feat: add scroll network messaging between l1 to l2
1 parent 6cbe969 commit 07d172e

File tree

4 files changed

+83
-16
lines changed

4 files changed

+83
-16
lines changed

contracts/contracts/L1Contract.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//SPDX-License-Identifier: Unlicense
2+
pragma solidity ^0.8.18;
3+
4+
contract L1Contract {
5+
// address l2Messenger = 0xb75d7e84517e1504C151B270255B087Fd746D34C;
6+
7+
event SendMessage(
8+
uint256 tokenId,
9+
address _to
10+
);
11+
12+
constructor() {}
13+
14+
function sendMessage(uint256 _tokenId, address _to) public {
15+
emit SendMessage(_tokenId, _to);
16+
}
17+
}

contracts/contracts/L2Contract.sol

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//SPDX-License-Identifier: Unlicense
2+
pragma solidity ^0.8.18;
3+
4+
// import "./IL2ScrollMessenger.sol";
5+
// import "./IL1Contract.sol";
6+
7+
contract L2Contract {
8+
9+
event ReceivedMessage(
10+
uint256 _tokentId,
11+
address _from
12+
);
13+
14+
constructor() {}
15+
16+
17+
function receiveMessage( uint256 _tokenId,address _from) public {
18+
emit ReceivedMessage(_tokenId,_from);
19+
}
20+
}

contracts/hardhat.config.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
require("@nomicfoundation/hardhat-toolbox");
2-
require("@nomiclabs/hardhat-ethers");
3-
require("hardhat-deploy");
4-
require("dotenv").config()
1+
require('@nomicfoundation/hardhat-toolbox');
2+
require('@nomiclabs/hardhat-ethers');
3+
require('hardhat-deploy');
4+
require('dotenv').config();
5+
6+
require('./tasks/task');
57

68
/** @type import('hardhat/config').HardhatUserConfig */
79
module.exports = {
8-
solidity: "0.8.18",
10+
solidity: '0.8.18',
911
paths: {
1012
artifacts: "artifacts",
1113
cache: "cache",
@@ -20,14 +22,14 @@ module.exports = {
2022
default: 0,
2123
},
2224
},
23-
networks: {
24-
goerli: {
25-
url: "https://eth-goerli.g.alchemy.com/v2/tmn4Rf7lh4ezew016QX0cDPAmAKb2KBz",
26-
accounts: [process.env.PRIVATE_KEY.toString()],
27-
chainId: 5
28-
},
29-
},
30-
etherscan: {
31-
apiKey: `${process.env.API_KEY}`
32-
}
33-
};
25+
// networks: {
26+
// goerli: {
27+
// url: "https://eth-goerli.g.alchemy.com/v2/tmn4Rf7lh4ezew016QX0cDPAmAKb2KBz",
28+
// accounts: [process.env.PRIVATE_KEY?.toString()],
29+
// chainId: 5
30+
// },
31+
// },
32+
// etherscan: {
33+
// apiKey: `${process.env.API_KEY}`
34+
// }
35+
};

contracts/tasks/task.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { task } = require('hardhat/config');
2+
3+
task('send', 'outbound transfer from polygon chain').setAction(
4+
async (_, hre) => {
5+
const ethers = hre.ethers;
6+
const L1Contract = await ethers.getContractFactory('L1Contract');
7+
const L1 = await L1Contract.deploy();
8+
const L2Contract = await ethers.getContractFactory('L2Contract');
9+
const L2 = await L2Contract.deploy();
10+
const { deployer } = await getNamedAccounts();
11+
12+
console.log('send message');
13+
console.log(
14+
await (
15+
await L1.sendMessage(0, '0xb75d7e84517e1504C151B270255B087Fd746D34C')
16+
).wait(),
17+
await (
18+
await L2.receiveMessage(
19+
0,
20+
'0xb75d7e84517e1504C151B270255B087Fd746D34C'
21+
)
22+
).wait()
23+
);
24+
25+
// console.log('receive message');
26+
// console.log(await (await L2Scroll.receiveMessage()).wait());
27+
}
28+
);

0 commit comments

Comments
 (0)