├── .env.sample
├── .github
└── workflows
│ └── test.yaml
├── .gitignore
├── LICENSE
├── README.md
├── contracts
├── Poster.sol
└── interfaces
│ ├── IPoster.sol
│ └── ISingletonFactory.sol
├── hardhat.config.ts
├── package.json
├── scripts
└── deploy.js
├── test
└── test.js
├── tsconfig.json
├── typechain
├── IPoster.d.ts
├── ISingletonFactory.d.ts
├── Poster.d.ts
├── commons.ts
├── factories
│ ├── IPoster__factory.ts
│ ├── ISingletonFactory__factory.ts
│ └── Poster__factory.ts
└── index.ts
└── yarn.lock
/.env.sample:
--------------------------------------------------------------------------------
1 | MNEMONIC=
2 | INFURA_KEY=
3 | MY_ETHERSCAN_API_KEY=
4 | PK=
5 |
--------------------------------------------------------------------------------
/.github/workflows/test.yaml:
--------------------------------------------------------------------------------
1 | name: Poster Test
2 |
3 | on:
4 | push:
5 | branches: ['**']
6 |
7 | jobs:
8 | test:
9 | name: Test contracts
10 | runs-on: ${{ matrix.os }}
11 |
12 | strategy:
13 | matrix:
14 | node-version: [16]
15 | os: ['ubuntu-latest']
16 |
17 | steps:
18 | - uses: actions/checkout@v2
19 | - name: Use Node.js ${{ matrix.node-version }}
20 | uses: actions/setup-node@v2
21 | with:
22 | node-version: ${{ matrix.node-version }}
23 | registry-url: https://registry.npmjs.org/
24 | cache: yarn
25 |
26 | - name: Install dependencies
27 | run: yarn
28 |
29 | - name: Build
30 | run: yarn build
31 |
32 | - name: Test
33 | run: yarn test
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | # cache
64 | cache
65 |
66 | # artifacts
67 | artifacts
68 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ```
2 | ██████╗ ██████╗ ███████╗████████╗███████╗██████╗
3 | ██╔══██╗██╔═══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗
4 | ██████╔╝██║ ██║███████╗ ██║ █████╗ ██████╔╝
5 | ██╔═══╝ ██║ ██║╚════██║ ██║ ██╔══╝ ██╔══██╗
6 | ██║ ╚██████╔╝███████║ ██║ ███████╗██║ ██║
7 | ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
8 | ```
9 |
10 | A ridiculously simple general purpose social media smart contract.
11 | It takes two strings (content and tag) as parameters and emits those strings, along with msg.sender, as an event. That's it.
12 |
13 | It is intended to be deployed on L2 Ethereum networks, or any EVM compatible network where gas is cheap/free.
14 |
15 | Poster v7 has been deployed at `0x000000000000cd17345801aa8147b8D3950260FF` on multiple networks using the [Singleton Factory](https://eips.ethereum.org/EIPS/eip-2470). If it is not yet deployed on your chosen network, you can use the Singleton Factory to deploy an instance of Poster at the same address on just about any EVM compatible network using these parameters:
16 |
17 | > **initCode:** `0x608060405234801561001057600080fd5b506101f6806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80630ae1b13d14610030575b600080fd5b61004361003e3660046100fa565b610045565b005b8181604051610055929190610163565b60405180910390203373ffffffffffffffffffffffffffffffffffffffff167f6c7f3182d7e4cb876251f9ae1489975fdbbf15d9f35d393f2ac9b1ff57cec69f86866040516100a5929190610173565b60405180910390a350505050565b60008083601f8401126100c4578182fd5b50813567ffffffffffffffff8111156100db578182fd5b6020830191508360208285010111156100f357600080fd5b9250929050565b6000806000806040858703121561010f578384fd5b843567ffffffffffffffff80821115610126578586fd5b610132888389016100b3565b9096509450602087013591508082111561014a578384fd5b50610157878288016100b3565b95989497509550505050565b6000828483379101908152919050565b60006020825282602083015282846040840137818301604090810191909152601f9092017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016010191905056fea2646970667358221220ee0377bd266748c5dbaf0a3f15ebd97be153932f2d14d460d9dd4271fee541b564736f6c63430008000033`
18 | >
19 | > **salt:** `0x9245db59943806d06245bc7847b3efb2c899d11b621a0f01bb02fd730e33aed2`
20 |
21 | When verifying on the source code on a block explorer, make sure to set the optimizer to `yes` and the runs to `10000000`.
22 |
23 | ---
24 |
25 | `Made with ❤️ by Auryn.eth`
26 |
--------------------------------------------------------------------------------
/contracts/Poster.sol:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ██████╗ ██████╗ ███████╗████████╗███████╗██████╗
4 | ██╔══██╗██╔═══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗
5 | ██████╔╝██║ ██║███████╗ ██║ █████╗ ██████╔╝
6 | ██╔═══╝ ██║ ██║╚════██║ ██║ ██╔══╝ ██╔══██╗
7 | ██║ ╚██████╔╝███████║ ██║ ███████╗██║ ██║
8 | ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
9 |
10 | A ridiculously simple general purpose social media smart contract.
11 | It takes two strings (content and tag) as parameters and emits those strings, along with msg.sender, as an event. That's it.
12 |
13 | Made with ❤️ by Auryn.eth
14 |
15 | */
16 | // SPDX-License-Identifier: LGPL-3.0-only
17 |
18 | pragma solidity 0.8.0;
19 |
20 |
21 | contract Poster {
22 | event NewPost(address indexed user, string content, string indexed tag);
23 |
24 | function post(string calldata content, string calldata tag) public {
25 | emit NewPost(msg.sender, content, tag);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/contracts/interfaces/IPoster.sol:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ██████╗ ██████╗ ███████╗████████╗███████╗██████╗
4 | ██╔══██╗██╔═══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗
5 | ██████╔╝██║ ██║███████╗ ██║ █████╗ ██████╔╝
6 | ██╔═══╝ ██║ ██║╚════██║ ██║ ██╔══╝ ██╔══██╗
7 | ██║ ╚██████╔╝███████║ ██║ ███████╗██║ ██║
8 | ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
9 |
10 | A ridiculously simple general purpose social media smart contract.
11 | It takes a string as a parameter and emits that string, along with msg.sender, as an event. That's it.
12 |
13 | Made with ❤️ by Auryn.eth
14 |
15 | */
16 | // SPDX-License-Identifier: LGPL-3.0-only
17 |
18 | pragma solidity 0.8.0;
19 |
20 |
21 | interface IPoster {
22 | event NewPost(address indexed user, string content);
23 |
24 | function post(string memory content) external;
25 | }
26 |
--------------------------------------------------------------------------------
/contracts/interfaces/ISingletonFactory.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: LGPL-3.0-only
2 |
3 | pragma solidity 0.8.0;
4 |
5 | interface ISingletonFactory {
6 | /// @dev Deploys `_initCode` using `_salt` for defining the deterministic address.
7 | /// @param _initCode Initialization code.
8 | /// @param _salt Arbitrary value to modify resulting address.
9 | /// @return createdContract Created contract address.
10 | function deploy(bytes memory _initCode, bytes32 _salt) external returns (address payable createdContract);
11 | }
12 |
--------------------------------------------------------------------------------
/hardhat.config.ts:
--------------------------------------------------------------------------------
1 | import "@nomiclabs/hardhat-waffle";
2 | import "hardhat-typechain";
3 | import "@tenderly/hardhat-tenderly";
4 | import dotenv from 'dotenv';
5 | import type { HttpNetworkUserConfig } from "hardhat/types";
6 | import { task } from "hardhat/config";
7 |
8 | dotenv.config();
9 | const { INFURA_KEY, MNEMONIC, ETHERSCAN_API_KEY, PK } = process.env;
10 |
11 | const DEFAULT_MNEMONIC =
12 | "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
13 |
14 | const sharedNetworkConfig: HttpNetworkUserConfig = {};
15 | if (PK) {
16 | sharedNetworkConfig.accounts = [PK];
17 | } else {
18 | sharedNetworkConfig.accounts = {
19 | mnemonic: MNEMONIC || DEFAULT_MNEMONIC,
20 | };
21 | }
22 |
23 | task('post', 'Creates a generic “microblog” post with a given content')
24 | .addParam('content', 'Specify the content of the message to post', undefined)
25 | .setAction(async ({ content }, hre) => {
26 | // NB: This is only possible because we know the target address.
27 | const poster = await hre.ethers.getContractAt("Poster", '0x000000000000cd17345801aa8147b8D3950260FF');
28 | const tag = "post";
29 | const post = `{"type":"microblog","text": "${content}"}`;
30 | const tx = await poster.post(post, tag);
31 | console.log('Transaction Hash', tx.hash);
32 | })
33 |
34 | module.exports = {
35 | networks: {
36 | localhost: {
37 | url: "http://localhost:8545",
38 | },
39 | mainnet: {
40 | ...sharedNetworkConfig,
41 | url: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
42 | },
43 | goerli: {
44 | ...sharedNetworkConfig,
45 | url: `https://goerli.infura.io/v3/${INFURA_KEY}`,
46 | },
47 | kovan: {
48 | ...sharedNetworkConfig,
49 | url: `https://kovan.infura.io/v3/${INFURA_KEY}`,
50 | },
51 | rinkeby: {
52 | ...sharedNetworkConfig,
53 | url: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
54 | },
55 | arb1: {
56 | ...sharedNetworkConfig,
57 | url: `https://arb1.arbitrum.io/rpc`,
58 | },
59 | optimism: {
60 | ...sharedNetworkConfig,
61 | url: `https://mainnet.optimism.io`,
62 | },
63 | polygon: {
64 | ...sharedNetworkConfig,
65 | url: `https://polygon-rpc.com`,
66 | },
67 | },
68 | namedAccounts: {
69 | deployer: 0,
70 | },
71 | mocha: {
72 | timeout: 2000000,
73 | },
74 | etherscan: {
75 | apiKey: ETHERSCAN_API_KEY,
76 | },
77 | solidity: {
78 | version: "0.8.0",
79 | settings: {
80 | optimizer: {
81 | enabled: true,
82 | runs: 10000000,
83 | },
84 | }
85 | }
86 | };
87 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Poster",
3 | "version": "7.0.0",
4 | "description": "A ridiculously simple general purpose social media smart contract. It takes two strings (content and tag) as parameters and emits those strings, along with msg.sender, as an event. That's it.",
5 | "author": "Auryn Macmillan ",
6 | "license": "LGPL-3.0+",
7 | "scripts": {
8 | "node": "hardhat node --network hardhat",
9 | "build": "hardhat compile",
10 | "test": "hardhat test",
11 | "deploy": "hardhat run scripts/deploy.js",
12 | "verify": "hardhat run scripts/verify.js",
13 | "task:post": "hardhat post --network localhost --content"
14 | },
15 | "devDependencies": {
16 | "@tenderly/hardhat-tenderly": "^1.0.13"
17 | },
18 | "dependencies": {
19 | "@nomiclabs/hardhat-ethers": "^2.0.2",
20 | "@nomiclabs/hardhat-etherscan": "^2.1.4",
21 | "@nomiclabs/hardhat-waffle": "^2.0.1",
22 | "@typechain/ethers-v5": "^6.0.5",
23 | "chai": "^4.3.4",
24 | "dotenv": "^8.2.0",
25 | "ethereum-waffle": "^3.3.0",
26 | "ethers": "^5.0.32",
27 | "hardhat": "2.6.0",
28 | "hardhat-typechain": "^0.3.5",
29 | "ts-generator": "^0.1.1",
30 | "ts-node": "^9.1.1",
31 | "typechain": "^4.0.3",
32 | "typescript": "^4.2.3"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/scripts/deploy.js:
--------------------------------------------------------------------------------
1 | const hre = require("hardhat");
2 |
3 | async function main() {
4 | const assert = require("assert");
5 |
6 | const salt =
7 | "0x9245db59943806d06245bc7847b3efb2c899d11b621a0f01bb02fd730e33aed2";
8 |
9 | const sfABI = [
10 | {
11 | constant: false,
12 | inputs: [
13 | {
14 | internalType: "bytes",
15 | name: "_initCode",
16 | type: "bytes"
17 | },
18 | {
19 | internalType: "bytes32",
20 | name: "_salt",
21 | type: "bytes32"
22 | }
23 | ],
24 | name: "deploy",
25 | outputs: [
26 | {
27 | internalType: "address payable",
28 | name: "createdContract",
29 | type: "address"
30 | }
31 | ],
32 | payable: false,
33 | stateMutability: "nonpayable",
34 | type: "function"
35 | }
36 | ];
37 |
38 | const wallet = await hre.ethers.getSigner();
39 | console.log("Using address: ", wallet.address);
40 |
41 | const singletonDeployer = "0xBb6e024b9cFFACB947A71991E386681B1Cd1477D";
42 | const singletonFactory = new hre.ethers.Contract(
43 | "0xce0042B868300000d44A59004Da54A005ffdcf9f",
44 | sfABI,
45 | wallet
46 | );
47 |
48 | // check if singleton factory is deplyed.
49 | if ((await hre.ethers.provider.getCode(singletonFactory.address)) === "0x") {
50 | // fund the singleton factory deployer account
51 | await wallet.sendTransaction({
52 | to: singletonDeployer,
53 | value: hre.ethers.utils.parseEther("0.0247")
54 | });
55 |
56 | // deploy the singleton factory
57 | await (await hre.ethers.provider.sendTransaction(
58 | "0xf9016c8085174876e8008303c4d88080b90154608060405234801561001057600080fd5b50610134806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634af63f0214602d575b600080fd5b60cf60048036036040811015604157600080fd5b810190602081018135640100000000811115605b57600080fd5b820183602082011115606c57600080fd5b80359060200191846001830284011164010000000083111715608d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550509135925060eb915050565b604080516001600160a01b039092168252519081900360200190f35b6000818351602085016000f5939250505056fea26469706673582212206b44f8a82cb6b156bfcc3dc6aadd6df4eefd204bc928a4397fd15dacf6d5320564736f6c634300060200331b83247000822470"
59 | )).wait();
60 |
61 | assert(
62 | (await hre.ethers.provider.getCode(singletonFactory.address)) != "0x"
63 | );
64 | }
65 | console.log("Singleton Factory deployed at:", singletonFactory.address);
66 |
67 | const Poster = await hre.ethers.getContractFactory("Poster");
68 |
69 | const targetAddress = await singletonFactory.callStatic.deploy(
70 | Poster.bytecode,
71 | salt
72 | );
73 | await singletonFactory.deploy(Poster.bytecode, salt, { gasLimit: 3000000 });
74 | const poster = await hre.ethers.getContractAt("Poster", targetAddress);
75 | assert(
76 | (await hre.ethers.provider.getCode(poster.address)) != "0x"
77 | );
78 | console.log("Poster deployed to: ", targetAddress);
79 | const tag = "post";
80 | const post =
81 | '{"type":"microblog","text":"Just deployed poster! 🎉"}';
82 | const tx = await poster.post(post, tag);
83 | console.log('Transaction Hash', tx.hash);
84 | }
85 |
86 | // We recommend this pattern to be able to use async/await everywhere
87 | // and properly handle errors.
88 | main()
89 | .then(() => process.exit(0))
90 | .catch(error => {
91 | console.error(error);
92 | process.exit(1);
93 | });
94 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | const { expect, assert } = require("chai");
2 |
3 | describe("Poster should:", function() {
4 | let deployer, user;
5 | before(async function() {
6 | [deployer, user, bob] = await ethers.getSigners();
7 | const Poster = await ethers.getContractFactory("Poster", deployer);
8 | poster = await Poster.deploy();
9 | expect(await poster.address);
10 | });
11 |
12 | it("emit an event when post() is called", async function() {
13 | let tag = "post";
14 | let content =
15 | '{"post":{"type":"microblog","text":"this is a post from user"}}';
16 | // Test that a NewPost event was emitted with the correct user, and content
17 | await expect(await poster.connect(user).post(content, tag))
18 | .to.emit(poster, "NewPost", tag)
19 | .withArgs(user.address, content, tag);
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2018",
4 | "module": "commonjs",
5 | "strict": true,
6 | "esModuleInterop": true,
7 | "outDir": "dist",
8 | "resolveJsonModule": true
9 | },
10 | "include": ["./scripts", "./tests"],
11 | "files": [
12 | "./hardhat.config.ts",
13 | "./node_modules/@nomiclabs/hardhat-ethers/src/type-extensions.d.ts",
14 | "./node_modules/@nomiclabs/hardhat-waffle/src/type-extensions.d.ts"
15 | ]
16 | }
--------------------------------------------------------------------------------
/typechain/IPoster.d.ts:
--------------------------------------------------------------------------------
1 | /* Autogenerated file. Do not edit manually. */
2 | /* tslint:disable */
3 | /* eslint-disable */
4 |
5 | import {
6 | ethers,
7 | EventFilter,
8 | Signer,
9 | BigNumber,
10 | BigNumberish,
11 | PopulatedTransaction,
12 | Contract,
13 | ContractTransaction,
14 | Overrides,
15 | CallOverrides,
16 | } from "ethers";
17 | import { BytesLike } from "@ethersproject/bytes";
18 | import { Listener, Provider } from "@ethersproject/providers";
19 | import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi";
20 | import { TypedEventFilter, TypedEvent, TypedListener } from "./commons";
21 |
22 | interface IPosterInterface extends ethers.utils.Interface {
23 | functions: {
24 | "post(string)": FunctionFragment;
25 | };
26 |
27 | encodeFunctionData(functionFragment: "post", values: [string]): string;
28 |
29 | decodeFunctionResult(functionFragment: "post", data: BytesLike): Result;
30 |
31 | events: {
32 | "NewPost(address,string)": EventFragment;
33 | };
34 |
35 | getEvent(nameOrSignatureOrTopic: "NewPost"): EventFragment;
36 | }
37 |
38 | export class IPoster extends Contract {
39 | connect(signerOrProvider: Signer | Provider | string): this;
40 | attach(addressOrName: string): this;
41 | deployed(): Promise;
42 |
43 | listeners, EventArgsObject>(
44 | eventFilter?: TypedEventFilter
45 | ): Array>;
46 | off, EventArgsObject>(
47 | eventFilter: TypedEventFilter,
48 | listener: TypedListener
49 | ): this;
50 | on, EventArgsObject>(
51 | eventFilter: TypedEventFilter,
52 | listener: TypedListener
53 | ): this;
54 | once, EventArgsObject>(
55 | eventFilter: TypedEventFilter,
56 | listener: TypedListener
57 | ): this;
58 | removeListener, EventArgsObject>(
59 | eventFilter: TypedEventFilter,
60 | listener: TypedListener
61 | ): this;
62 | removeAllListeners, EventArgsObject>(
63 | eventFilter: TypedEventFilter
64 | ): this;
65 |
66 | listeners(eventName?: string): Array;
67 | off(eventName: string, listener: Listener): this;
68 | on(eventName: string, listener: Listener): this;
69 | once(eventName: string, listener: Listener): this;
70 | removeListener(eventName: string, listener: Listener): this;
71 | removeAllListeners(eventName?: string): this;
72 |
73 | queryFilter, EventArgsObject>(
74 | event: TypedEventFilter,
75 | fromBlockOrBlockhash?: string | number | undefined,
76 | toBlock?: string | number | undefined
77 | ): Promise>>;
78 |
79 | interface: IPosterInterface;
80 |
81 | functions: {
82 | post(
83 | content: string,
84 | overrides?: Overrides & { from?: string | Promise }
85 | ): Promise;
86 |
87 | "post(string)"(
88 | content: string,
89 | overrides?: Overrides & { from?: string | Promise }
90 | ): Promise;
91 | };
92 |
93 | post(
94 | content: string,
95 | overrides?: Overrides & { from?: string | Promise }
96 | ): Promise;
97 |
98 | "post(string)"(
99 | content: string,
100 | overrides?: Overrides & { from?: string | Promise }
101 | ): Promise;
102 |
103 | callStatic: {
104 | post(content: string, overrides?: CallOverrides): Promise;
105 |
106 | "post(string)"(content: string, overrides?: CallOverrides): Promise;
107 | };
108 |
109 | filters: {
110 | NewPost(
111 | user: string | null,
112 | content: null
113 | ): TypedEventFilter<[string, string], { user: string; content: string }>;
114 | };
115 |
116 | estimateGas: {
117 | post(
118 | content: string,
119 | overrides?: Overrides & { from?: string | Promise }
120 | ): Promise;
121 |
122 | "post(string)"(
123 | content: string,
124 | overrides?: Overrides & { from?: string | Promise }
125 | ): Promise;
126 | };
127 |
128 | populateTransaction: {
129 | post(
130 | content: string,
131 | overrides?: Overrides & { from?: string | Promise }
132 | ): Promise;
133 |
134 | "post(string)"(
135 | content: string,
136 | overrides?: Overrides & { from?: string | Promise }
137 | ): Promise;
138 | };
139 | }
140 |
--------------------------------------------------------------------------------
/typechain/ISingletonFactory.d.ts:
--------------------------------------------------------------------------------
1 | /* Autogenerated file. Do not edit manually. */
2 | /* tslint:disable */
3 | /* eslint-disable */
4 |
5 | import {
6 | ethers,
7 | EventFilter,
8 | Signer,
9 | BigNumber,
10 | BigNumberish,
11 | PopulatedTransaction,
12 | Contract,
13 | ContractTransaction,
14 | Overrides,
15 | CallOverrides,
16 | } from "ethers";
17 | import { BytesLike } from "@ethersproject/bytes";
18 | import { Listener, Provider } from "@ethersproject/providers";
19 | import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi";
20 | import { TypedEventFilter, TypedEvent, TypedListener } from "./commons";
21 |
22 | interface ISingletonFactoryInterface extends ethers.utils.Interface {
23 | functions: {
24 | "deploy(bytes,bytes32)": FunctionFragment;
25 | };
26 |
27 | encodeFunctionData(
28 | functionFragment: "deploy",
29 | values: [BytesLike, BytesLike]
30 | ): string;
31 |
32 | decodeFunctionResult(functionFragment: "deploy", data: BytesLike): Result;
33 |
34 | events: {};
35 | }
36 |
37 | export class ISingletonFactory extends Contract {
38 | connect(signerOrProvider: Signer | Provider | string): this;
39 | attach(addressOrName: string): this;
40 | deployed(): Promise;
41 |
42 | listeners, EventArgsObject>(
43 | eventFilter?: TypedEventFilter
44 | ): Array>;
45 | off, EventArgsObject>(
46 | eventFilter: TypedEventFilter,
47 | listener: TypedListener
48 | ): this;
49 | on, EventArgsObject>(
50 | eventFilter: TypedEventFilter,
51 | listener: TypedListener
52 | ): this;
53 | once, EventArgsObject>(
54 | eventFilter: TypedEventFilter,
55 | listener: TypedListener
56 | ): this;
57 | removeListener, EventArgsObject>(
58 | eventFilter: TypedEventFilter,
59 | listener: TypedListener
60 | ): this;
61 | removeAllListeners, EventArgsObject>(
62 | eventFilter: TypedEventFilter
63 | ): this;
64 |
65 | listeners(eventName?: string): Array;
66 | off(eventName: string, listener: Listener): this;
67 | on(eventName: string, listener: Listener): this;
68 | once(eventName: string, listener: Listener): this;
69 | removeListener(eventName: string, listener: Listener): this;
70 | removeAllListeners(eventName?: string): this;
71 |
72 | queryFilter, EventArgsObject>(
73 | event: TypedEventFilter,
74 | fromBlockOrBlockhash?: string | number | undefined,
75 | toBlock?: string | number | undefined
76 | ): Promise>>;
77 |
78 | interface: ISingletonFactoryInterface;
79 |
80 | functions: {
81 | deploy(
82 | _initCode: BytesLike,
83 | _salt: BytesLike,
84 | overrides?: Overrides & { from?: string | Promise }
85 | ): Promise;
86 |
87 | "deploy(bytes,bytes32)"(
88 | _initCode: BytesLike,
89 | _salt: BytesLike,
90 | overrides?: Overrides & { from?: string | Promise }
91 | ): Promise;
92 | };
93 |
94 | deploy(
95 | _initCode: BytesLike,
96 | _salt: BytesLike,
97 | overrides?: Overrides & { from?: string | Promise }
98 | ): Promise;
99 |
100 | "deploy(bytes,bytes32)"(
101 | _initCode: BytesLike,
102 | _salt: BytesLike,
103 | overrides?: Overrides & { from?: string | Promise }
104 | ): Promise;
105 |
106 | callStatic: {
107 | deploy(
108 | _initCode: BytesLike,
109 | _salt: BytesLike,
110 | overrides?: CallOverrides
111 | ): Promise;
112 |
113 | "deploy(bytes,bytes32)"(
114 | _initCode: BytesLike,
115 | _salt: BytesLike,
116 | overrides?: CallOverrides
117 | ): Promise;
118 | };
119 |
120 | filters: {};
121 |
122 | estimateGas: {
123 | deploy(
124 | _initCode: BytesLike,
125 | _salt: BytesLike,
126 | overrides?: Overrides & { from?: string | Promise }
127 | ): Promise;
128 |
129 | "deploy(bytes,bytes32)"(
130 | _initCode: BytesLike,
131 | _salt: BytesLike,
132 | overrides?: Overrides & { from?: string | Promise }
133 | ): Promise;
134 | };
135 |
136 | populateTransaction: {
137 | deploy(
138 | _initCode: BytesLike,
139 | _salt: BytesLike,
140 | overrides?: Overrides & { from?: string | Promise }
141 | ): Promise;
142 |
143 | "deploy(bytes,bytes32)"(
144 | _initCode: BytesLike,
145 | _salt: BytesLike,
146 | overrides?: Overrides & { from?: string | Promise }
147 | ): Promise;
148 | };
149 | }
150 |
--------------------------------------------------------------------------------
/typechain/Poster.d.ts:
--------------------------------------------------------------------------------
1 | /* Autogenerated file. Do not edit manually. */
2 | /* tslint:disable */
3 | /* eslint-disable */
4 |
5 | import {
6 | ethers,
7 | EventFilter,
8 | Signer,
9 | BigNumber,
10 | BigNumberish,
11 | PopulatedTransaction,
12 | Contract,
13 | ContractTransaction,
14 | Overrides,
15 | CallOverrides,
16 | } from "ethers";
17 | import { BytesLike } from "@ethersproject/bytes";
18 | import { Listener, Provider } from "@ethersproject/providers";
19 | import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi";
20 | import { TypedEventFilter, TypedEvent, TypedListener } from "./commons";
21 |
22 | interface PosterInterface extends ethers.utils.Interface {
23 | functions: {
24 | "post(string,string)": FunctionFragment;
25 | };
26 |
27 | encodeFunctionData(
28 | functionFragment: "post",
29 | values: [string, string]
30 | ): string;
31 |
32 | decodeFunctionResult(functionFragment: "post", data: BytesLike): Result;
33 |
34 | events: {
35 | "NewPost(address,string,string)": EventFragment;
36 | };
37 |
38 | getEvent(nameOrSignatureOrTopic: "NewPost"): EventFragment;
39 | }
40 |
41 | export class Poster extends Contract {
42 | connect(signerOrProvider: Signer | Provider | string): this;
43 | attach(addressOrName: string): this;
44 | deployed(): Promise;
45 |
46 | listeners, EventArgsObject>(
47 | eventFilter?: TypedEventFilter
48 | ): Array>;
49 | off, EventArgsObject>(
50 | eventFilter: TypedEventFilter,
51 | listener: TypedListener
52 | ): this;
53 | on, EventArgsObject>(
54 | eventFilter: TypedEventFilter,
55 | listener: TypedListener
56 | ): this;
57 | once, EventArgsObject>(
58 | eventFilter: TypedEventFilter,
59 | listener: TypedListener
60 | ): this;
61 | removeListener, EventArgsObject>(
62 | eventFilter: TypedEventFilter,
63 | listener: TypedListener
64 | ): this;
65 | removeAllListeners, EventArgsObject>(
66 | eventFilter: TypedEventFilter
67 | ): this;
68 |
69 | listeners(eventName?: string): Array;
70 | off(eventName: string, listener: Listener): this;
71 | on(eventName: string, listener: Listener): this;
72 | once(eventName: string, listener: Listener): this;
73 | removeListener(eventName: string, listener: Listener): this;
74 | removeAllListeners(eventName?: string): this;
75 |
76 | queryFilter, EventArgsObject>(
77 | event: TypedEventFilter,
78 | fromBlockOrBlockhash?: string | number | undefined,
79 | toBlock?: string | number | undefined
80 | ): Promise>>;
81 |
82 | interface: PosterInterface;
83 |
84 | functions: {
85 | post(
86 | content: string,
87 | tag: string,
88 | overrides?: Overrides & { from?: string | Promise }
89 | ): Promise;
90 |
91 | "post(string,string)"(
92 | content: string,
93 | tag: string,
94 | overrides?: Overrides & { from?: string | Promise }
95 | ): Promise;
96 | };
97 |
98 | post(
99 | content: string,
100 | tag: string,
101 | overrides?: Overrides & { from?: string | Promise }
102 | ): Promise;
103 |
104 | "post(string,string)"(
105 | content: string,
106 | tag: string,
107 | overrides?: Overrides & { from?: string | Promise }
108 | ): Promise;
109 |
110 | callStatic: {
111 | post(
112 | content: string,
113 | tag: string,
114 | overrides?: CallOverrides
115 | ): Promise;
116 |
117 | "post(string,string)"(
118 | content: string,
119 | tag: string,
120 | overrides?: CallOverrides
121 | ): Promise;
122 | };
123 |
124 | filters: {
125 | NewPost(
126 | user: string | null,
127 | content: null,
128 | tag: string | null
129 | ): TypedEventFilter<
130 | [string, string, string],
131 | { user: string; content: string; tag: string }
132 | >;
133 | };
134 |
135 | estimateGas: {
136 | post(
137 | content: string,
138 | tag: string,
139 | overrides?: Overrides & { from?: string | Promise }
140 | ): Promise;
141 |
142 | "post(string,string)"(
143 | content: string,
144 | tag: string,
145 | overrides?: Overrides & { from?: string | Promise }
146 | ): Promise;
147 | };
148 |
149 | populateTransaction: {
150 | post(
151 | content: string,
152 | tag: string,
153 | overrides?: Overrides & { from?: string | Promise }
154 | ): Promise;
155 |
156 | "post(string,string)"(
157 | content: string,
158 | tag: string,
159 | overrides?: Overrides & { from?: string | Promise }
160 | ): Promise;
161 | };
162 | }
163 |
--------------------------------------------------------------------------------
/typechain/commons.ts:
--------------------------------------------------------------------------------
1 | /* Autogenerated file. Do not edit manually. */
2 | /* tslint:disable */
3 | /* eslint-disable */
4 |
5 | import { EventFilter, Event } from "ethers";
6 | import { Result } from "@ethersproject/abi";
7 |
8 | export interface TypedEventFilter<_EventArgsArray, _EventArgsObject>
9 | extends EventFilter {}
10 |
11 | export interface TypedEvent extends Event {
12 | args: EventArgs;
13 | }
14 |
15 | export type TypedListener<
16 | EventArgsArray extends Array,
17 | EventArgsObject
18 | > = (
19 | ...listenerArg: [
20 | ...EventArgsArray,
21 | TypedEvent
22 | ]
23 | ) => void;
24 |
--------------------------------------------------------------------------------
/typechain/factories/IPoster__factory.ts:
--------------------------------------------------------------------------------
1 | /* Autogenerated file. Do not edit manually. */
2 | /* tslint:disable */
3 | /* eslint-disable */
4 |
5 | import { Contract, Signer } from "ethers";
6 | import { Provider } from "@ethersproject/providers";
7 |
8 | import type { IPoster } from "../IPoster";
9 |
10 | export class IPoster__factory {
11 | static connect(
12 | address: string,
13 | signerOrProvider: Signer | Provider
14 | ): IPoster {
15 | return new Contract(address, _abi, signerOrProvider) as IPoster;
16 | }
17 | }
18 |
19 | const _abi = [
20 | {
21 | anonymous: false,
22 | inputs: [
23 | {
24 | indexed: true,
25 | internalType: "address",
26 | name: "user",
27 | type: "address",
28 | },
29 | {
30 | indexed: false,
31 | internalType: "string",
32 | name: "content",
33 | type: "string",
34 | },
35 | ],
36 | name: "NewPost",
37 | type: "event",
38 | },
39 | {
40 | inputs: [
41 | {
42 | internalType: "string",
43 | name: "content",
44 | type: "string",
45 | },
46 | ],
47 | name: "post",
48 | outputs: [],
49 | stateMutability: "nonpayable",
50 | type: "function",
51 | },
52 | ];
53 |
--------------------------------------------------------------------------------
/typechain/factories/ISingletonFactory__factory.ts:
--------------------------------------------------------------------------------
1 | /* Autogenerated file. Do not edit manually. */
2 | /* tslint:disable */
3 | /* eslint-disable */
4 |
5 | import { Contract, Signer } from "ethers";
6 | import { Provider } from "@ethersproject/providers";
7 |
8 | import type { ISingletonFactory } from "../ISingletonFactory";
9 |
10 | export class ISingletonFactory__factory {
11 | static connect(
12 | address: string,
13 | signerOrProvider: Signer | Provider
14 | ): ISingletonFactory {
15 | return new Contract(address, _abi, signerOrProvider) as ISingletonFactory;
16 | }
17 | }
18 |
19 | const _abi = [
20 | {
21 | inputs: [
22 | {
23 | internalType: "bytes",
24 | name: "_initCode",
25 | type: "bytes",
26 | },
27 | {
28 | internalType: "bytes32",
29 | name: "_salt",
30 | type: "bytes32",
31 | },
32 | ],
33 | name: "deploy",
34 | outputs: [
35 | {
36 | internalType: "address payable",
37 | name: "createdContract",
38 | type: "address",
39 | },
40 | ],
41 | stateMutability: "nonpayable",
42 | type: "function",
43 | },
44 | ];
45 |
--------------------------------------------------------------------------------
/typechain/factories/Poster__factory.ts:
--------------------------------------------------------------------------------
1 | /* Autogenerated file. Do not edit manually. */
2 | /* tslint:disable */
3 | /* eslint-disable */
4 |
5 | import { Signer, Contract, ContractFactory, Overrides } from "ethers";
6 | import { Provider, TransactionRequest } from "@ethersproject/providers";
7 |
8 | import type { Poster } from "../Poster";
9 |
10 | export class Poster__factory extends ContractFactory {
11 | constructor(signer?: Signer) {
12 | super(_abi, _bytecode, signer);
13 | }
14 |
15 | deploy(
16 | overrides?: Overrides & { from?: string | Promise }
17 | ): Promise {
18 | return super.deploy(overrides || {}) as Promise;
19 | }
20 | getDeployTransaction(
21 | overrides?: Overrides & { from?: string | Promise }
22 | ): TransactionRequest {
23 | return super.getDeployTransaction(overrides || {});
24 | }
25 | attach(address: string): Poster {
26 | return super.attach(address) as Poster;
27 | }
28 | connect(signer: Signer): Poster__factory {
29 | return super.connect(signer) as Poster__factory;
30 | }
31 | static connect(address: string, signerOrProvider: Signer | Provider): Poster {
32 | return new Contract(address, _abi, signerOrProvider) as Poster;
33 | }
34 | }
35 |
36 | const _abi = [
37 | {
38 | anonymous: false,
39 | inputs: [
40 | {
41 | indexed: true,
42 | internalType: "address",
43 | name: "user",
44 | type: "address",
45 | },
46 | {
47 | indexed: false,
48 | internalType: "string",
49 | name: "content",
50 | type: "string",
51 | },
52 | {
53 | indexed: true,
54 | internalType: "string",
55 | name: "tag",
56 | type: "string",
57 | },
58 | ],
59 | name: "NewPost",
60 | type: "event",
61 | },
62 | {
63 | inputs: [
64 | {
65 | internalType: "string",
66 | name: "content",
67 | type: "string",
68 | },
69 | {
70 | internalType: "string",
71 | name: "tag",
72 | type: "string",
73 | },
74 | ],
75 | name: "post",
76 | outputs: [],
77 | stateMutability: "nonpayable",
78 | type: "function",
79 | },
80 | ];
81 |
82 | const _bytecode =
83 | "0x608060405234801561001057600080fd5b506101f6806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80630ae1b13d14610030575b600080fd5b61004361003e3660046100fa565b610045565b005b8181604051610055929190610163565b60405180910390203373ffffffffffffffffffffffffffffffffffffffff167f6c7f3182d7e4cb876251f9ae1489975fdbbf15d9f35d393f2ac9b1ff57cec69f86866040516100a5929190610173565b60405180910390a350505050565b60008083601f8401126100c4578182fd5b50813567ffffffffffffffff8111156100db578182fd5b6020830191508360208285010111156100f357600080fd5b9250929050565b6000806000806040858703121561010f578384fd5b843567ffffffffffffffff80821115610126578586fd5b610132888389016100b3565b9096509450602087013591508082111561014a578384fd5b50610157878288016100b3565b95989497509550505050565b6000828483379101908152919050565b60006020825282602083015282846040840137818301604090810191909152601f9092017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016010191905056fea2646970667358221220ee0377bd266748c5dbaf0a3f15ebd97be153932f2d14d460d9dd4271fee541b564736f6c63430008000033";
84 |
--------------------------------------------------------------------------------
/typechain/index.ts:
--------------------------------------------------------------------------------
1 | /* Autogenerated file. Do not edit manually. */
2 | /* tslint:disable */
3 | /* eslint-disable */
4 | export type { IPoster } from "./IPoster";
5 | export type { ISingletonFactory } from "./ISingletonFactory";
6 | export type { Poster } from "./Poster";
7 |
8 | export { IPoster__factory } from "./factories/IPoster__factory";
9 | export { ISingletonFactory__factory } from "./factories/ISingletonFactory__factory";
10 | export { Poster__factory } from "./factories/Poster__factory";
11 |
--------------------------------------------------------------------------------