Skip to content

Commit 48224d4

Browse files
authored
Merge pull request #738 from Web3Auth/fix/web3js-sign-msg-v4
fix/code to signing a msg in web3.js (eth_signTypedData_v4)
2 parents 644a2c0 + 1f7f975 commit 48224d4

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

src/common/docs/web-connect-blockchain/_evm-sign-message-v4.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import Tabs from "@theme/Tabs";
1111
<TabItem value="web3">
1212

1313
```tsx
14+
import { Eip712TypedData } from "web3/lib/types"
15+
...
16+
1417
/*
1518
Sign Typed Data v4 adds support for
1619
arrays and recursive data types.
@@ -27,9 +30,9 @@ import Tabs from "@theme/Tabs";
2730
// Get user's Ethereum public address
2831
const fromAddress = (await web3.eth.getAccounts())[0];
2932

30-
const originalMessage = JSON.stringify({
33+
const originalMessage:Eip712TypedData = {
3134
domain: {
32-
// Defining the chain aka Sepolia testnet or Ethereum Main Net
35+
// Defining the same active chain Id
3336
chainId: 11155111, // 1 for mainnet
3437
// Give a user friendly name to the specific contract you are signing for.
3538
name: "Ether Mail",
@@ -91,15 +94,9 @@ const originalMessage = JSON.stringify({
9194
{ name: "wallets", type: "address[]" },
9295
],
9396
},
94-
});
95-
const params = [fromAddress, originalMessage];
96-
const method = "eth_signTypedData_v4";
97+
};
9798

98-
const signedMessage = await web3.currentProvider.sendAsync({
99-
method,
100-
params,
101-
fromAddress,
102-
});
99+
const signedMessage = await web3.eth.signTypedData(fromAddress, originalMessage)
103100
```
104101

105102
</TabItem>
@@ -141,7 +138,10 @@ const originalMessage = JSON.stringify({
141138
attachedMoneyInEth: 4.2,
142139
from: {
143140
name: "Cow",
144-
wallets: ["0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"],
141+
wallets: [
142+
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
143+
"0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF",
144+
],
145145
},
146146
to: [
147147
{

0 commit comments

Comments
 (0)