Skip to content

Commit 1fb32bd

Browse files
feature: migrate from ethers to viem (wip)
1 parent 70b5794 commit 1fb32bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1447
-706
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.md
2+
**/dist/**
3+
**/build/**

demos/taco-demo/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"build": "pnpm clean && webpack --mode production --progress",
1010
"clean": "rimraf build",
1111
"check": "pnpm type-check && pnpm build",
12-
"type-check": "tsc --noEmit"
12+
"type-check": "tsc --noEmit",
13+
"lint": "eslint --ext .ts src",
14+
"lint:fix": "pnpm lint --fix"
1315
},
1416
"dependencies": {
1517
"@nucypher/taco": "^0.1.0-rc.6",
@@ -21,7 +23,8 @@
2123
"react": "^18.2.0",
2224
"react-copy-to-clipboard": "^5.1.0",
2325
"react-dom": "^18.2.0",
24-
"react-spinners": "^0.13.6"
26+
"react-spinners": "^0.13.6",
27+
"viem": "^1.19.9"
2528
},
2629
"devDependencies": {
2730
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
@@ -34,7 +37,7 @@
3437
"react-refresh": "^0.14.0",
3538
"rimraf": "^5.0.5",
3639
"stream-browserify": "^3.0.0",
37-
"typescript": "^4.8.3",
40+
"typescript": "^5.2.2",
3841
"webpack": "^5.89.0",
3942
"webpack-cli": "^5.1.4",
4043
"webpack-dev-server": "^4.11.1"

demos/taco-demo/src/App.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import {
88
ThresholdMessageKit,
99
} from '@nucypher/taco';
1010
import { Mumbai, useEthers } from '@usedapp/core';
11-
import { ethers } from 'ethers';
1211
import React, { useEffect, useState } from 'react';
12+
import 'viem/window';
13+
14+
import { createPublicClient, createWalletClient, custom } from 'viem';
1315

1416
import { ConditionBuilder } from './ConditionBuilder';
17+
import { DEFAULT_DOMAIN, DEFAULT_RITUAL_ID } from './config';
1518
import { Decrypt } from './Decrypt';
1619
import { Encrypt } from './Encrypt';
1720
import { Spinner } from './Spinner';
18-
import { DEFAULT_DOMAIN, DEFAULT_RITUAL_ID } from './config';
1921

2022
export default function App() {
2123
const { activateBrowserWallet, deactivate, account, switchNetwork } =
@@ -36,42 +38,60 @@ export default function App() {
3638
}, []);
3739

3840
const encryptMessage = async (message: string) => {
41+
if (!window.ethereum) {
42+
console.error('You need to connect to your wallet first');
43+
return;
44+
}
3945
if (!condition) {
4046
return;
4147
}
4248
setLoading(true);
4349

4450
await switchNetwork(Mumbai.chainId);
4551

46-
const provider = new ethers.providers.Web3Provider(window.ethereum);
52+
const publicClient = createPublicClient({
53+
transport: custom(window.ethereum),
54+
});
55+
const walletClient = createWalletClient({
56+
transport: custom(window.ethereum),
57+
});
4758
const encryptedMessage = await encrypt(
48-
provider,
59+
publicClient,
4960
domain,
5061
message,
5162
condition,
5263
ritualId,
53-
provider.getSigner(),
64+
walletClient,
5465
);
5566

5667
setEncryptedMessage(encryptedMessage);
5768
setLoading(false);
5869
};
5970

6071
const decryptMessage = async (encryptedMessage: ThresholdMessageKit) => {
72+
if (!window.ethereum) {
73+
console.error('You need to connect to your wallet first');
74+
return;
75+
}
6176
if (!condition) {
6277
return;
6378
}
6479
setLoading(true);
6580
setDecryptedMessage('');
6681
setDecryptionErrors([]);
6782

68-
const provider = new ethers.providers.Web3Provider(window.ethereum);
83+
const publicClient = createPublicClient({
84+
transport: custom(window.ethereum),
85+
});
86+
const walletClient = createWalletClient({
87+
transport: custom(window.ethereum),
88+
});
6989
const decryptedMessage = await decrypt(
70-
provider,
90+
publicClient,
7191
domain,
7292
encryptedMessage,
7393
getPorterUri(domain),
74-
provider.getSigner(),
94+
walletClient,
7595
);
7696

7797
setDecryptedMessage(new TextDecoder().decode(decryptedMessage));

demos/taco-demo/src/react-app-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

demos/taco-demo/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ module.exports = {
3333
DEFAULT_RITUAL_ID: JSON.stringify(process.env.DEFAULT_RITUAL_ID),
3434
DEFAULT_DOMAIN: JSON.stringify(process.env.DEFAULT_DOMAIN),
3535
},
36-
}
37-
})
36+
},
37+
}),
3838
].filter(Boolean),
3939
module: {
4040
rules: [

demos/taco-nft-demo/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"build": "pnpm clean && webpack --mode production --progress",
1010
"clean": "rimraf build",
1111
"check": "pnpm type-check && pnpm build",
12-
"type-check": "tsc --noEmit"
12+
"type-check": "tsc --noEmit",
13+
"lint": "eslint --ext .ts src",
14+
"lint:fix": "pnpm lint --fix"
1315
},
1416
"dependencies": {
1517
"@nucypher/taco": "^0.1.0-rc.6",
@@ -21,7 +23,8 @@
2123
"react": "^18.2.0",
2224
"react-copy-to-clipboard": "^5.1.0",
2325
"react-dom": "^18.2.0",
24-
"react-spinners": "^0.13.6"
26+
"react-spinners": "^0.13.6",
27+
"viem": "^1.19.9"
2528
},
2629
"devDependencies": {
2730
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
@@ -34,7 +37,7 @@
3437
"react-refresh": "^0.14.0",
3538
"rimraf": "^5.0.5",
3639
"stream-browserify": "^3.0.0",
37-
"typescript": "^4.8.3",
40+
"typescript": "^5.2.2",
3841
"webpack": "^5.89.0",
3942
"webpack-cli": "^5.1.4",
4043
"webpack-dev-server": "^4.11.1"

demos/taco-nft-demo/src/App.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import {
88
ThresholdMessageKit,
99
} from '@nucypher/taco';
1010
import { Mumbai, useEthers } from '@usedapp/core';
11-
import { ethers } from 'ethers';
1211
import React, { useEffect, useState } from 'react';
12+
import 'viem/window';
13+
import { createPublicClient, createWalletClient, custom } from 'viem';
1314

1415
import { Decrypt } from './Decrypt';
1516
import { Encrypt } from './Encrypt';
@@ -35,42 +36,60 @@ export default function App() {
3536
}, []);
3637

3738
const encryptMessage = async (message: string) => {
39+
if (!window.ethereum) {
40+
console.error('You need to connect to your wallet first');
41+
return;
42+
}
3843
if (!condition) {
3944
return;
4045
}
4146
setLoading(true);
4247

4348
await switchNetwork(Mumbai.chainId);
4449

45-
const provider = new ethers.providers.Web3Provider(window.ethereum);
50+
const publicClient = createPublicClient({
51+
transport: custom(window.ethereum),
52+
});
53+
const walletClient = createWalletClient({
54+
transport: custom(window.ethereum),
55+
});
4656
const encryptedMessage = await encrypt(
47-
provider,
57+
publicClient,
4858
domain,
4959
message,
5060
condition,
5161
ritualId,
52-
provider.getSigner(),
62+
walletClient,
5363
);
5464

5565
setEncryptedMessage(encryptedMessage);
5666
setLoading(false);
5767
};
5868

5969
const decryptMessage = async (encryptedMessage: ThresholdMessageKit) => {
70+
if (!window.ethereum) {
71+
console.error('You need to connect to your wallet first');
72+
return;
73+
}
6074
if (!condition) {
6175
return;
6276
}
6377
setLoading(true);
6478
setDecryptedMessage('');
6579
setDecryptionErrors([]);
6680

67-
const provider = new ethers.providers.Web3Provider(window.ethereum);
81+
const publicClient = createPublicClient({
82+
transport: custom(window.ethereum),
83+
});
84+
const walletClient = createWalletClient({
85+
transport: custom(window.ethereum),
86+
});
6887
const decryptedMessage = await decrypt(
69-
provider,
88+
publicClient,
7089
domain,
7190
encryptedMessage,
7291
getPorterUri(domain),
73-
provider.getSigner(),
92+
walletClient,
7493
);
7594

7695
setDecryptedMessage(new TextDecoder().decode(decryptedMessage));

demos/taco-nft-demo/src/react-app-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

demos/taco-nft-demo/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ module.exports = {
3333
DEFAULT_RITUAL_ID: JSON.stringify(process.env.DEFAULT_RITUAL_ID),
3434
DEFAULT_DOMAIN: JSON.stringify(process.env.DEFAULT_DOMAIN),
3535
},
36-
}
37-
})
36+
},
37+
}),
3838
].filter(Boolean),
3939
module: {
4040
rules: [

examples/pre/nextjs/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
},
1212
"dependencies": {
1313
"@nucypher/pre": "workspace:*",
14+
"next": "14.0.3",
15+
"react": "18.2.0",
16+
"react-dom": "18.2.0",
17+
"viem": "^1.19.9"
18+
},
19+
"devDependencies": {
1420
"@types/node": "20.10.0",
1521
"@types/react": "18.2.45",
1622
"@types/react-dom": "18.2.14",

0 commit comments

Comments
 (0)