Skip to content

Instantly share code, notes, and snippets.

View swkim109's full-sized avatar
🍊
Stale

swkim109

🍊
Stale
View GitHub Profile
@swkim109
swkim109 / Impl.sol
Last active February 21, 2022 23:48
supportedInterfaces
//SPDX-License-Identifier:MIT
pragma solidity 0.7.6;
interface ERC721 /* is ERC165 */ {
/// @dev This emits when ownership of any NFT changes by any mechanism.
/// This event emits when NFTs are created (`from` == 0) and destroyed
/// (`to` == 0). Exception: during contract creation, any number of NFTs
/// may be created and assigned without emitting Transfer. At the time of
/// any transfer, the approved address for that NFT (if any) is reset to none.
@swkim109
swkim109 / blockhash.py
Created June 3, 2021 20:43
Bitcoin blockhash
import hashlib
# block info
v = "20000000"
pHash = "0000000000000000001113e97e93bd818554382f16d089a81371c6873a0b92b6"
mroot = "f765e73e351ef8ed6c0f09c2b2c48b87fee449ac41582193f757f0327a1d65e3"
ts = 1558398995 # convert human readable time to timestamp in https://www.epochconverter.com/
bits = 388627269
n = 3231819810
@swkim109
swkim109 / controller.js
Created August 7, 2021 05:21
server-side signing using ethereumjs-tx
const ethTx = require('ethereumjs-tx').Transaction;
const Web3 = require('web3');
const { GANACHE_WS, GANACHE_NETWORK_ID } = require('./eth.config');
const Common = require('ethereumjs-common').default;
let NETWORK_ID;
let PROVIDER;
if (process.env.NODE_ENV === "development") {
//PROVIDER = GANACHE_WS;
//NETWORK_ID = GANACHE_NETWORK_ID;
@swkim109
swkim109 / eth.controller.js
Created August 18, 2021 23:36
@ethereumjs/common
const ethTx = require('@ethereumjs/tx').Transaction;
const Common = require('@ethereumjs/common').default;
const {bufferToHex} = require('ethereumjs-util');
const Web3 = require('web3');
const { GANACHE_WS, GANACHE_NETWORK_ID } = require('./eth.config');
let NETWORK_ID;
let PROVIDER;
if (process.env.NODE_ENV === "development") {
PROVIDER = GANACHE_WS;
@swkim109
swkim109 / sign.js
Last active December 5, 2022 09:26
Sign message
const Web3 = require('web3');
const HDWalletProvider = require("@truffle/hdwallet-provider");
const fs = require('fs');
const key = fs.readFileSync("private.key").toString().trim();
const privateKeys = [key];
//const mnemonic = "crash ... twice";
// 지갑을 쓰는 것과 동일
const provider = new HDWalletProvider({
@swkim109
swkim109 / TokenRecipient.sol
Created February 28, 2022 05:35
TokenRecipient
//SPDX-License-Identifier:MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract TokenRecipient {
address owner;
event ReceivedEther(address indexed sender, uint256 value);
@swkim109
swkim109 / Greeter.sol
Created March 22, 2022 00:57
JS Test in Remix
//SPDX-License-Identifier:MIT
pragma solidity ^0.8.0;
contract Greeter {
struct Member {
uint256 id;
string name;
}
@swkim109
swkim109 / hash.js
Created June 16, 2022 02:03
해시 함수 keccak256
// 모두 동일한 해시
console.log(web3.utils.keccak256("Kate"));
console.log(web3.utils.sha3("Kate"));
console.log(web3.utils.soliditySha3("Kate"));
console.log(ethers.utils.keccak256(ethers.utils.toUtf8Bytes("Kate")));
// 솔리디티
// 0.5.0 이후부터는 sha3()가 없어짐
keccak256("Kate");
@swkim109
swkim109 / MyContract.sol
Last active July 15, 2022 08:25
0.6.0 vs 0.8.0
// SPDX-License-Identifier: MIT
//pragma solidity ^0.8.0;
pragma solidity ^0.6.0;
contract MyContract {
function f() public pure {
int8 x = -2**7;
assert(x == -x);
}
@swkim109
swkim109 / MyStructArray.sol
Created July 15, 2022 08:30
struct array
//SPDX-License-Identifier:MIT
pragma solidity ^0.8.0;
contract MyContract {
struct Member {
uint256 age;
string name;
}