Skip to content

Instantly share code, notes, and snippets.

Avatar

Yukishige Nakajo nakajo2011

View GitHub Profile
@nakajo2011
nakajo2011 / App.tsx
Created May 3, 2021
Apollo Client/Getting Started sample4
View App.tsx
import React from 'react';
import './App.css';
import './ExchangeRates'
import ExchangeRates from "./ExchangeRates";
export default function App() {
return (
<div>
<h2>My first Apollo app 🚀</h2>
@nakajo2011
nakajo2011 / index.tsx
Created May 3, 2021
Apollo Client/Getting Started sample3
View index.tsx
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import fetch from 'cross-fetch';
import { gql, ApolloProvider, ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';
const endpoint = 'https://48p1r2roz4.sse.codesandbox.io' // apolloのGetting Started
@nakajo2011
nakajo2011 / ExchangeRates.tsx
Last active May 3, 2021
Apollo Client/Getting Started sample2
View ExchangeRates.tsx
import {gql, useQuery} from '@apollo/client';
const EXCHANGE_RATES = gql`
query GetExchangeRates {
rates(currency: "USD") {
currency
rate
}
}
`;
@nakajo2011
nakajo2011 / index.mjs
Last active May 3, 2021
Apollo Client/Getting Started sample
View index.mjs
import fetch from 'cross-fetch';
import { gql, ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';
const client = new ApolloClient({
link: new HttpLink({ uri: 'https://48p1r2roz4.sse.codesandbox.io', fetch }),
cache: new InMemoryCache()
});
client
.query({
query: gql`
query GetRates {
@nakajo2011
nakajo2011 / ModExp.sol
Created Mar 16, 2021
ModExp sample on Solidity
View ModExp.sol
pragma solidity ^0.8.1;
contract ModExpContracts {
address public constant modExpAddress = 0x0000000000000000000000000000000000000005;
bytes public _result;
function modExp(
uint baseLength,
@nakajo2011
nakajo2011 / PanicTest.sol
Last active Feb 24, 2021
GBEC 2021.02.25 sample code
View PanicTest.sol
pragma solidity >= 0.8.0;
contract CalledContract {
uint[] nums;
function onlyEven(uint256 a) external pure returns(uint) {
uint b = 300 / a;
require(b % 2 == 0, "Ups! Reverting");
return b;
@nakajo2011
nakajo2011 / miner_stop_correct_test.js
Created Jul 7, 2020
arround freeze sendTransaction.
View miner_stop_correct_test.js
const pify = require('pify')
async function queueTransaction(from, to, value, nonce, gasLimit, data) {
const response = await pify(web3.currentProvider.send)({
jsonrpc: "2.0",
method: "eth_sendTransaction",
id: new Date().getTime(),
params: [
{
from: from,
@nakajo2011
nakajo2011 / miner_stop_test.js
Last active Jul 7, 2020
miner.stop test, but it happen error.
View miner_stop_test.js
it('multi transfer in same block', async () => {
web3.extend({property: 'mine', methods: [{ name: 'start', call: 'miner_start', params:0}]})
web3.extend({property: 'mine', methods: [{ name: 'stop', call: 'miner_stop', params:0}]})
const instance = await MyERC20Token.new()
const beforeBlock = await web3.eth.getBlockNumber()
await web3.mine.stop()
// queued tx1
@nakajo2011
nakajo2011 / SimpleDonationManager.sol
Last active May 27, 2020
Using immutable keyword
View SimpleDonationManager.sol
pragma solidity >=0.6.5;
contract SimpleDonationManager {
uint256 immutable minDonation = 42;
uint256 immutable maxDonation = calcMaxDonation();
address immutable owner;
constructor() public {
owner = msg.sender;
// Error: Immutables cannot be read in constructor.
// assert(minDonation <= maxDonation);
// Error: Immutables can only be assigned once.
@nakajo2011
nakajo2011 / 1.web3.js
Created Apr 9, 2020
mock web3.js using jest
View 1.web3.js
/* Mock web3 as __tests__/__mocks__/web3.js */
// const web3 = jest.genMockFromModule('web3')
/* Mock web3-eth-contract */
let mockWeb3EthContract = function() {}
function __setMockContract(mock) {
mockWeb3EthContract = mock
}
let blockNumber = 0