Commit 84376c37 authored by luxq's avatar luxq

Initial commit

parents
Pipeline #551 failed with stages
node_modules
.env
coverage
coverage.json
typechain
#Hardhat files
cache
artifacts
# Basic Sample Hardhat Project
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts.
Try running some of the following tasks:
```shell
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
node scripts/sample-script.js
npx hardhat help
```
// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract GLDToken is ERC20 {
bytes32 dephash;
bytes32 lasthash;
event MintMore(address, address, uint256);
constructor(uint256 initialSupply) ERC20("Gold", "GLD") {
dephash = blockhash(block.number);
lasthash = blockhash(block.number-1);
_mint(msg.sender, initialSupply);
}
function mint(address user, uint256 mintSuplly) public {
_mint(user, mintSuplly);
emit MintMore(msg.sender, user, mintSuplly);
}
function gethash() public view returns (bytes32 , bytes32 ) {
return (lasthash, dephash);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
contract MQQ is Initializable, ERC721Upgradeable, OwnableUpgradeable, UUPSUpgradeable {
using CountersUpgradeable for CountersUpgradeable.Counter;
CountersUpgradeable.Counter private _tokenIdCounter;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() initializer {}
function initialize() initializer public {
__ERC721_init("MQQ", "MQQ");
__Ownable_init();
__UUPSUpgradeable_init();
}
function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
function _authorizeUpgrade(address newImplementation)
internal
onlyOwner
override
{}
}
// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MTMToken is ERC20 {
address admin;
constructor(uint256 initialSupply) ERC20("MTMT", "MTMT") {
_mint(msg.sender, initialSupply);
}
function mint(uint256 mintSuplly) public {
require(msg.sender == admin, "only admin can mint");
_mint(msg.sender, mintSuplly);
}
function name() public view override returns (string memory) {
return "MTMT";
}
function symbol() public view override returns (string memory) {
return "MTMT";
}
function decimals() public view override returns (uint8 ) {
return 8;
}
}
require("@nomiclabs/hardhat-waffle");
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
// Define mnemonic for accounts.
let mnemonic = process.env.MNEMONIC;
if (!mnemonic) {
// NOTE: this fallback is for development only!
// When using other networks, set the secret in .env.
// DO NOT commit or share your mnemonic with others!
mnemonic = 'test test test test test test test test test test test test';
}
let privateKey = process.env.PRIVATE_KEY;
const accounts = { mnemonic };
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.8.4",
networks: {
hardhat: {
accounts,
gas: 10000000,
gasPrice: 10000000000,
},
testnet: {
url: 'https://galaxy.block.caduceus.foundation',
accounts: [privateKey]
},
local: {
url: 'http://127.0.0.1:8545',
accounts: [privateKey],
}
},
};
This diff is collapsed.
{
"name": "testcontract",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "^4.3.3",
"chai": "^4.3.4",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.5.1",
"hardhat": "^2.6.8"
},
"dependencies": {
"@openzeppelin/contracts-upgradeable": "^4.5.2"
}
}
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const txargs = { gasLimit: 10000000, gasPrice: 5000000000 }
var transfers = [
"0x0335dc2E445D864F8076f5C16C3D545666997Cc6",
//"0x138e0257ad83d575fec08c90c87f2fa8638c0e23",
//"0x1094ebd9ea2e025aad9e2c5e45c73f9aa7adfcfc",
//"0x0f183b333fc178d43cc06bf8b163923ffad70ace",
//"0x0d8c29e55af50e35477f5be023a9a86c62e4a971"
//"0x0e4189874daacfcb6dc2c24463cd4a75d3b726c7",
//"0x8f8fc9ff531434a1b5f8f46c9dd263172d469e32",
//"0xa861ac8e7009d250e777b7e27671dfa0e269efe1",
//"0xf3ea9d758e66607016252790d0e53a114d1a5901",
//"0xa95b3759d62366b1af8655312c26db90a874a784",
//"0xbfd4ce233c8b2c93ab982fc71f7000301c9a56b4",
//"0xa9eeb63c4c00682cdcab70fc8752b8a1edcccd05",
//"0xc1d5f2d45dd8f62b46c28e03fa1d44bfcc96e2a5",
//"0xa33011d35ab7368067b3d3999075947d85bb1046",
//"0xd2e7a867312324c3c79e80ad1a441df89cd3f29d",
//"0x8e93949af3dcd48ed38dd0f6c487027e1d18e2ff",
//"0xbab0d36f2fddaa4473fc55c7a0ee30ca8845434f",
//"0xab496263eb6be9e0dc9f56ec4d05e8546f419ba8",
//"0xd834b5aa5a18b4b71e2d45cee55265206bbba061",
//"0xd353168b3ffb1f898f1fae857b8962bf1973c431",
//"0xbc31bfde367203f601633d4d08bc952f7e95da39",
//"0xcd01b140310859e8043c6e589e162881dd54b35c",
//"0xfcb5ee2928fbe4c6805da81cfb4afb60a350b751"
]
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
const accounts = await hre.ethers.getSigners();
console.log("use account ", accounts[0].address);
// We get the contract to deploy
const GLDToken = await hre.ethers.getContractFactory("GLDToken");
const gldToken = await GLDToken.deploy("10000000000000000000000000");
var tx = await gldToken.deployed({ gasprice: 10000000000, gas: 10000000 });
console.log("GLDToken deployed to:", gldToken.address );
var hashs = await gldToken.gethash();
console.log("get hash ", hashs);
for (var i =0; i < 1; i++) {
for (let addr of transfers) {
var mint = await gldToken.mint(addr, "200000000000");
await mint.wait();
console.log("mint gldtoken to ", addr);
var tr = await gldToken.transfer(addr, "1000000000000000000");
await tr.wait();
console.log("transfer gldtoken to ", addr);
}
}
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const txargs = { gasLimit: 10000000, gasPrice: 5000000000 }
var transfers = [
"0x138e0257ad83d575fec08c90c87f2fa8638c0e23",
"0x1094ebd9ea2e025aad9e2c5e45c73f9aa7adfcfc",
"0x0f183b333fc178d43cc06bf8b163923ffad70ace",
"0x0d8c29e55af50e35477f5be023a9a86c62e4a971",
"0x0e4189874daacfcb6dc2c24463cd4a75d3b726c7",
"0x8f8fc9ff531434a1b5f8f46c9dd263172d469e32",
"0xa861ac8e7009d250e777b7e27671dfa0e269efe1",
"0xf3ea9d758e66607016252790d0e53a114d1a5901",
"0xa95b3759d62366b1af8655312c26db90a874a784",
"0xbfd4ce233c8b2c93ab982fc71f7000301c9a56b4",
"0xa9eeb63c4c00682cdcab70fc8752b8a1edcccd05",
"0xc1d5f2d45dd8f62b46c28e03fa1d44bfcc96e2a5",
"0xa33011d35ab7368067b3d3999075947d85bb1046",
"0xd2e7a867312324c3c79e80ad1a441df89cd3f29d",
"0x8e93949af3dcd48ed38dd0f6c487027e1d18e2ff",
"0xbab0d36f2fddaa4473fc55c7a0ee30ca8845434f",
"0xab496263eb6be9e0dc9f56ec4d05e8546f419ba8",
"0xd834b5aa5a18b4b71e2d45cee55265206bbba061",
"0xd353168b3ffb1f898f1fae857b8962bf1973c431",
"0xbc31bfde367203f601633d4d08bc952f7e95da39",
"0xcd01b140310859e8043c6e589e162881dd54b35c",
"0xfcb5ee2928fbe4c6805da81cfb4afb60a350b751"
]
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
const accounts = await hre.ethers.getSigners();
console.log("use account ", accounts[0].address);
// We get the contract to deploy
const MTMToken = await hre.ethers.getContractFactory("MTMToken");
const mtmToken = await MTMToken.deploy("30000000000000000000000000");
await mtmToken.deployed();
console.log("MTMToken deployed to:", mtmToken.address);
for (var i =0; i < 100000; i++) {
console.log("goto mint")
var mint = await mtmToken.mint("200000000000");
await mint.wait();
for (let addr of transfers) {
console.log("goto transfer")
var tr = await mtmToken.transfer(addr, "1000000000000000000");
await tr.wait();
console.log("transfer mtmtoken to ", addr);
}
}
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const txargs = { gasLimit: 10000000, gasPrice: 5000000000 }
var transfers = [
"0x138e0257ad83d575fec08c90c87f2fa8638c0e23",
"0x1094ebd9ea2e025aad9e2c5e45c73f9aa7adfcfc",
"0x0f183b333fc178d43cc06bf8b163923ffad70ace",
"0x0d8c29e55af50e35477f5be023a9a86c62e4a971",
"0x0e4189874daacfcb6dc2c24463cd4a75d3b726c7",
"0x8f8fc9ff531434a1b5f8f46c9dd263172d469e32",
"0xa861ac8e7009d250e777b7e27671dfa0e269efe1",
"0xf3ea9d758e66607016252790d0e53a114d1a5901",
"0xa95b3759d62366b1af8655312c26db90a874a784",
"0xbfd4ce233c8b2c93ab982fc71f7000301c9a56b4",
"0xa9eeb63c4c00682cdcab70fc8752b8a1edcccd05",
"0xc1d5f2d45dd8f62b46c28e03fa1d44bfcc96e2a5",
"0xa33011d35ab7368067b3d3999075947d85bb1046",
"0xd2e7a867312324c3c79e80ad1a441df89cd3f29d",
"0x8e93949af3dcd48ed38dd0f6c487027e1d18e2ff",
"0xbab0d36f2fddaa4473fc55c7a0ee30ca8845434f",
"0xab496263eb6be9e0dc9f56ec4d05e8546f419ba8",
"0xd834b5aa5a18b4b71e2d45cee55265206bbba061",
"0xd353168b3ffb1f898f1fae857b8962bf1973c431",
"0xbc31bfde367203f601633d4d08bc952f7e95da39",
"0xcd01b140310859e8043c6e589e162881dd54b35c",
"0xfcb5ee2928fbe4c6805da81cfb4afb60a350b751"
]
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
const accounts = await hre.ethers.getSigners();
console.log("use account ", accounts[0].address);
// We get the contract to deploy
const MQQToken = await hre.ethers.getContractFactory("MQQ");
const mqqToken = await MQQToken.deploy();
await mqqToken.deployed({ gasprice: 10000000000, gas: 10000000 });
console.log("MQQToken deployed to:", mqqToken.address);
for (var i =0; i < 100000; i++) {
for (let addr of transfers) {
var mint = await mqqToken.safeMint(accounts[0].address, txargs);
await mint.wait();
var tr = await mqqToken.transfer(addr, i, txargs);
await tr.wait();
console.log("transfer mqqtoken to ", addr);
}
}
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const txargs = { gasLimit: 10000000, gasPrice: 5000000000 }
async function main() {
const accounts = await hre.ethers.getSigners();
console.log("use account ", accounts[0].address);
// We get the contract to deploy
var addr = "0x59a758a899634F03533F55C7f7A63BA1BEAb5E59";
const gldToken = await hre.ethers.getContractAt("GLDToken", addr);
// gldToken.events.BreedingOfHorse({ fromBlock: 872988 }, function(error, event) { console.log(event); })
// .on("connected", function(subscriptionId) {
// console.log(subscriptionId);
// }).on('data', function(event) {
// console.log(event); // same results as the optional callback above
// })
// .on('changed', function(event) {
// // remove event from local database
// })
const mint = await gldToken.mint("200000000000", txargs);
var receipt = await mint.wait();
console.log("mint tx finished, receipt is ", receipt);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
\ No newline at end of file
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
// We get the contract to deploy
const Greeter = await hre.ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
await greeter.deployed();
console.log("Greeter deployed to:", greeter.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
const Web3 = require('web3');
const web3 = new Web3('http://35.179.4.20:8580');
const contractAddress = '0x77E62D6f753DCd292c3DCC8469d5365EBa580bBd';
const contractAbi = require('./c.abi');
const contract = new web3.eth.Contract(contractAbi, contractAddress);
const PAST_EVENT = async () => {
//await contract.getPastEvents("allEvents",{fromBlock:"312000",toBlock:"latest"});
await contract.getPastEvents("allEvents",
{
fromBlock: "312000",
toBlock: "latest",
},
(err, events) => {
console.log(events);
});
};
PAST_EVENT();
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("Greeter", function () {
it("Should return the new greeting once it's changed", async function () {
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");
await greeter.deployed();
expect(await greeter.greet()).to.equal("Hello, world!");
const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
// wait until the transaction is mined
await setGreetingTx.wait();
expect(await greeter.greet()).to.equal("Hola, mundo!");
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment