Skip to content

Instantly share code, notes, and snippets.

View blutarche's full-sized avatar
🌞
sunshine and mortality

Aik blutarche

🌞
sunshine and mortality
  • Software Engineer @Cleverse
  • Bangkok, Thailand
  • 13:37 (UTC +07:00)
View GitHub Profile
import { ethers } from "hardhat";
async function main() {
const LoveLetter = await ethers.getContractFactory("LoveLetter");
const loveLetter = await LoveLetter.deploy();
await loveLetter.deployed();
console.log("LoveLetter deployed to:", loveLetter.address);
}
import { expect } from "chai";
import { Signer, utils } from "ethers";
import { ethers } from "hardhat";
import { LoveLetter } from "../typechain";
describe("LoveLetter", () => {
let love: LoveLetter;
let sender: Signer;
let receiver: Signer;
let stranger: Signer;
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract LoveLetter {
uint256 public totalLetters;
mapping(uint256 => address) public senders;
mapping(uint256 => address) public receivers;
struct Letter {
contract LoveLetter {
...
function readMessage(uint256 id)
external
view
returns (string memory message)
{
message = letters[id].message;
}
contract LoveLetter {
...
function open(uint256 id) external returns (string memory message) {
require(receivers[id] == msg.sender, "Not receiver");
require(!letters[id].opened, "Already opened");
message = letters[id].message;
letters[id].opened = true;
uint256 amount = letters[id].etherAmount;
console.log("[open]", id, amount);
contract LoveLetter {
...
function send(address to, string memory message)
external
payable
returns (uint256 id)
{
id = totalLetters;
senders[id] = msg.sender;
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract LoveLetter {
uint256 public totalLetters;
mapping(uint256 => address) public senders;
mapping(uint256 => address) public receivers;
struct Letter {
@blutarche
blutarche / LoveLetter-base.sol
Last active July 4, 2022 08:15
Solidity x Hardhat 101
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract LoveLetter {
uint256 public totalLetters;
mapping(uint256 => address) public senders;
mapping(uint256 => address) public receivers;
struct Letter {
function: Deposit
parameters: Amount, Deadline
code:
- Check if function Caller transfer asset to this contract by at least the Amount.
- if not, reject transaction
- Increase function Caller's balance by Amount.
- Lock this chunk of asset with the deadline.
function: Withdraw
parameters: Amount
#include"cstdio"
#include"iostream"
using namespace std;
# define N 1001
int day[N][N] = {0}, minute[N][N] = {0};
void print(int n) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {