Skip to content

Commit

Permalink
replace ethers with viem, add wagmi, working ui
Browse files Browse the repository at this point in the history
  • Loading branch information
e00dan committed Jan 19, 2024
1 parent f9526f2 commit c01a69a
Show file tree
Hide file tree
Showing 14 changed files with 2,842 additions and 1,700 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/wagmi-generated.ts
69 changes: 69 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-env node */
module.exports = {
env: {
browser: true,
es6: true,
node: true,
mocha: true
},
extends: [
'airbnb-base',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
BigInt: 'readonly'
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/camelcase': 'off',
'no-await-in-loop': 'off',
'no-plusplus': 'off',
'no-console': 'off',
'no-continue': 'off',
'import/prefer-default-export': 'off',
'no-restricted-syntax': 'off',
'no-constant-condition': 'off',
'class-methods-use-this': 'off',
'no-underscore-dangle': 'off',
'no-bitwise': 'off',
'no-restricted-properties': 'off',
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never'
}
],
'import/no-extraneous-dependencies': 'off',
'no-useless-constructor': 'off',
'react/prop-types': 'off',
'react/jsx-no-target-blank': 'off'
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts']
}
},
react: {
pragma: 'React',
version: 'detect'
}
}
};
73 changes: 0 additions & 73 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ node_modules
dist
build
.openzeppelin/.session
typechain-types
artifacts
cache
cache
src/wagmi-generated.ts
7 changes: 1 addition & 6 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import '@typechain/hardhat';
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-waffle';
import '@nomicfoundation/hardhat-viem';

export default {
solidity: '0.8.9',
typechain: {
target: 'ethers-v5'
},
networks: {
hardhat: {
accounts: {
Expand Down
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"test": "test"
},
"scripts": {
"build": "yarn compile && yarn build:ts",
"build": "yarn compile && yarn wagmi generate && yarn build:ts",
"build:ts": "tsc -b tsconfig.build.json --verbose --pretty",
"clean": "shx rm -rf artifacts build cache dist typechain-types",
"clean": "shx rm -rf artifacts build cache dist",
"compile": "hardhat compile",
"lint": "eslint .",
"start": "ts-node src/HeadTail.ts",
"start:ethereum": "hardhat node",
"test": "mocha -r ts-node/register src/test/*.test.ts --timeout 60000 --exit",
Expand All @@ -27,36 +28,34 @@
},
"types": "dist/js/src/index.d.ts",
"dependencies": {
"ethers": "^5.1.3"
"viem": "^2.4.0"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "2.0.5",
"@nomiclabs/hardhat-waffle": "2.0.2",
"@typechain/ethers-v5": "9.0.0",
"@typechain/hardhat": "4.0.0",
"@nomicfoundation/hardhat-viem": "^1.0.2",
"@types/chai": "4.2.9",
"@types/mocha": "9.1.0",
"@types/node": "14.14.11",
"@types/react": "16.9.21",
"@types/react-dom": "16.9.5",
"@types/webpack-dev-server": "^4.1.0",
"@typescript-eslint/eslint-plugin": "2.19.2",
"@typescript-eslint/parser": "2.19.2",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"@wagmi/cli": "^2.0.4",
"assert": "^2.0.0",
"chai": "^4.3.6",
"cross-env": "7.0.0",
"crypto-browserify": "^3.12.0",
"css-loader": "3.4.2",
"eslint": "6.8.0",
"eslint-config-airbnb-base": "14.0.0",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "6.10.0",
"eslint-plugin-import": "2.20.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "3.1.2",
"eslint-plugin-react": "7.18.3",
"ethlint": "1.2.5",
"extract-text-webpack-plugin": "3.0.2",
"fork-ts-checker-webpack-plugin": "4.0.4",
"hardhat": "^2.8.4",
"hardhat": "2.19.4",
"html-webpack-plugin": "5.3.1",
"https-browserify": "^1.0.0",
"mocha": "^9.2.1",
Expand All @@ -71,8 +70,7 @@
"style-loader": "1.1.3",
"ts-loader": "6.2.1",
"ts-node": "8.6.2",
"typechain": "7.0.0",
"typescript": "4.5.5",
"typescript": "5.3.2",
"vm-browserify": "^1.1.2",
"webpack": "5.52.0",
"webpack-cli": "4.6.0",
Expand Down
40 changes: 34 additions & 6 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
import { providers } from 'ethers';
import { HeadTail__factory } from '../typechain-types';
import { CustomTransport, Hex, WalletClient, getContract, getContractAddress } from 'viem';
import { hardhat } from 'viem/chains';
import { headTailAbi } from './wagmi-generated';
import { publicClient } from './config';
import { bytecode } from '../artifacts/contracts/HeadTail.sol/HeadTail.json';

export async function deployHeadTailContract(rpc: providers.JsonRpcProvider, from: string) {
const signer = rpc.getSigner(from);
const factory = new HeadTail__factory(signer);
export async function deployHeadTailContract(
walletClient: WalletClient<CustomTransport, typeof hardhat>
) {
if (!walletClient.account) {
throw new Error('account is none');
}

return factory.deploy();
const transactionCount = await publicClient.getTransactionCount({
address: walletClient.account.address
});

const contractAddress = getContractAddress({
from: walletClient.account.address,
nonce: BigInt(transactionCount)
});

await walletClient.deployContract({
abi: headTailAbi,
account: walletClient.account,
bytecode: bytecode as Hex
});

return getContract({
address: contractAddress,
abi: headTailAbi,
client: {
public: publicClient,
wallet: walletClient
}
});
}
8 changes: 8 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { HttpTransport, PublicClient, createPublicClient, http } from 'viem';
import { hardhat } from 'viem/chains';

export const CONFIG = {
WEB3_PROVIDER_URL: 'http://localhost:8545'
};

export const publicClient: PublicClient<HttpTransport, typeof hardhat> = createPublicClient({
chain: hardhat,
transport: http()
});
9 changes: 0 additions & 9 deletions src/test/HeadTail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,23 @@ describe('HeadTail', () => {
describe('Stage 1', () => {
// it('allows to deposit 1 ETH', async () => {
// const account = accounts[0];

// const startingBalance = (await rpc.getBalance(account)).toBigInt();

// console.log({
// startingBalance
// });

// const oneEther = BigInt(1 * 10 ** 18);

// await contract.deposit({
// value: Number(oneEther)
// });

// const finalBalance = (await rpc.getBalance(account)).toBigInt();
// expect(finalBalance).to.be.equal(startingBalance - oneEther);
// });

// it('saves address of user', async () => {
// const account = accounts[0];

// const oneEther = BigInt(1 * 10 ** 18);

// await contract.deposit({
// value: Number(oneEther)
// });

// expect(await contract.userAddress()).to.be.equal(account);
// });
});
Expand Down
10 changes: 10 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export {};

type EthereumProvider = { request(...args: any): Promise<any> };

declare global {
interface Window {
ethereum?: EthereumProvider;
}
}
Loading

0 comments on commit c01a69a

Please sign in to comment.