Skip to content

Instantly share code, notes, and snippets.

View steadylearner's full-sized avatar
🏠
Working remotely

Steadylearner steadylearner

🏠
Working remotely
View GitHub Profile
@steadylearner
steadylearner / snippets.js
Created November 11, 2021 13:59 — forked from beautyfree/snippets.js
Solana Web3 Snippets
import {
Account,
clusterApiUrl,
Connection,
PublicKey,
sendAndConfirmTransaction,
SystemProgram,
Transaction,
} from '@solana/web3.js';
import { useEffect, useState, createRef } from 'react';
import { Contract, ethers } from 'ethers'
import moment from "moment";
import { Container, Dimmer, Loader, Grid, Sticky, Message } from 'semantic-ui-react';
import 'semantic-ui-css/semantic.min.css';
import Escrow from './artifacts/contracts/Escrow.sol/Escrow.json'
const { expect } = require("chai");
const { expectRevert } = require('@openzeppelin/test-helpers');
const humanReadableUnixTimestamp = (timestampInt) => {
return new Date(timestampInt * 1000);
}
describe("Escrow Events and State", function() {
// 1.
let provider;
let Escrow, escrow, seller, firstBuyer, secondBuyer; // seller is owner
let closedEvent,
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Escrow {
uint public price;
address payable public seller;
address payable public buyer;
// 1.
address[] previousBuyers;
// 2.
enum State { Sale, Locked, Release, Closed, Complete }
// ethers is global variable here.
const { expect } = require("chai");
const { expectRevert } = require('@openzeppelin/test-helpers');
// 1.
const totalSupplyBigNumberHex = ethers.BigNumber.from("0x52b7d2dcc80cd2e4000000");
const preMineBigNumberHex = ethers.BigNumber.from("0x108b2a2c28029094000000");
const airDropSize = "1000000000000000000000000"; // "0xD3C21BCECCEDA1000000"
describe("SCAMToken state and transactions", function () {
let SCAMToken, scamToken, owner, firstComer, secondComer; // seller is owner
// We don't include events here
// 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 `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
async function main() {
const [deployer] = await hre.ethers.getSigners();
console.log(
"Deploying contracts with the account:",
pragma solidity >=0.4.22 <0.6.0;
contract SCAM_Token {
// 1.
string public constant name = "Safe Crypto And Money";
string public constant symbol = "SCAM";
uint8 public constant decimals = 18;
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
pragma solidity >=0.4.22 <0.6.0;
contract SCAM_Token {
// 1.
string public constant name = "Safe Crypto And Money";
string public constant symbol = "SCAM";
uint8 public constant decimals = 18;
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);