Skip to content

Instantly share code, notes, and snippets.

View mingderwang's full-sized avatar
:bowtie:
On chain, building L2

Ming-der Wang mingderwang

:bowtie:
On chain, building L2
View GitHub Profile
// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.24 and less than 0.9.0
pragma solidity ^0.8.24;
contract HelloWorld {
string public greet = "Hello World!";
}
@mingderwang
mingderwang / index.html
Created March 6, 2024 16:17
refer to https://simplewebauthn.dev/docs/packages/browser (code is generated by ChatGPT in openAI)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web Authentication Example</title>
</head>
<body>
<script>
exports.endpoint = (req, res) => {
const html = `
<!-- Example 1: Preact in HTML (no build tooling required!) -->
<!-- View Code: https://glitch.com/edit/#!/familiar-warm-monday -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@mingderwang
mingderwang / Timestamp.sol
Last active February 17, 2024 16:08
Timestamp test
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.7;
contract Timestamp {
uint public timestamp;
function saveTimestamp() public {
timestamp = block.timestamp;
}
}
const { ethers } = require("ethers");
const encoder = (types, values) => {
const abiCoder = ethers.utils.defaultAbiCoder;
const encodedParams = abiCoder.encode(types, values);
return encodedParams.slice(2);
};
const create2Address = (factoryAddress, saltHex, initCode) => {
const create2Addr = ethers.utils.getCreate2Address(factoryAddress, saltHex, ethers.utils.keccak256(initCode));
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract DeterministicDeployFactory {
event Deploy(address addr);
function deploy(bytes memory bytecode, uint _salt) external {
address addr;
assembly {
addr := create2(0, add(bytecode, 0x20), mload(bytecode), _salt)
@mingderwang
mingderwang / SimpleAccount.sol
Created February 9, 2024 04:48
test ethereum ERC4337 SimpleAccount.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
/* solhint-disable avoid-low-level-calls */
/* solhint-disable no-inline-assembly */
/* solhint-disable reason-string */
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract CountEmitLog {
event WantsToCount(address indexed msgSender);
constructor() {}
function emitCountLog() public {
emit WantsToCount(msg.sender);
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
/// @custom:security-contact [email protected]
contract My721Token is ERC721URIStorage, Ownable {
uint256 private _nextTokenId;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/// @custom:security-contact [email protected]
contract My721Token is ERC721URIStorage, Ownable {
uint256 private _nextTokenId;