Using Ethers.js to Sign and Recover EIP-712 Typed Structured Data
Solidity - EIP-712 Typed Structured Data Hashing and Signing explains how smart contracts verify the signature of EIP-712. This article explains how to use Ethers.js for EIP-712 signing. This article uses Ethers.js version 6.7.1. Signsigner.signTypedDataEthers.js uses the following function to sign. Refer to the previous article Using Ethers.js to Sign and Recover to obtain the Signer. 1signer.signTypedData(domain, types, value): Promise<string> domain: The data of eip712Domain in the con ...
Using Web3.js to Sign and Recover EIP-712 Typed Structured Data
Solidity - EIP-712 Typed Structured Data Hashing and Signing explains how smart contracts verify the signature of EIP-712. This article explains how to use Web3.js for EIP-712 signing. This article uses Web3.js version 4.1.1. SignBrowser WalletWeb3.js can use the following functions to sign EIP-712: web3.eth.signTypedData web3.currentProvider.request Browser wallets can use the above functions, but Web3.js does not have a private key signing method, so another library will be introduced later ...
Solidity - EIP-712 Typed Structured Data Hashing and Signing
This article explains the EIP-712 standard and how to use Solidity to implement EIP-712 in smart contract. IntroductionIn the previous article, we introduced some methods of signing and verification. In practice, we may sign many data. For example: 123456789function permit(address owner, address spender, uint value, uint nonce, uint deadline, uint8 v, bytes32 r, bytes32 s) external { require(deadline >= block.timestamp, "signature expired"); require(!usedNonces[nonce], " ...
Using Ethers.js to Sign and Recover
Solidity - ecrecover this article explains how smart contracts verify signatures. This article will explain how to use Ethers.js to sign and recover. This article uses Ethers.js version 6.7.1. SignerThe Signer object will be used in the following content. Here is a brief explanation of how to obtain it. Private Key12345import { JsonRpcProvider, Wallet } from "ethers";const privateKey = '0x...'const provider = new JsonRpcProvider(url);const signer = new Wallet(privat ...
Using Web3.js to Sign and Recover
Solidity - ecrecover this article explains how smart contracts verify signatures. This article will explain how to use Web3.js to sign and recover. This article uses Web3.js version 4.1.1. SignWeb3.js provides several off-chain signing functions. This article introduces the following three: web3.eth.sign web3.eth.accounts.sign web3.personal.sign For EIP-712 related methods, refer to Using Web3.js to Sign and Recover EIP-712 Typed Structured Data. web3.eth.signThis is an old function, and the s ...
Solidity - Signature Malleability
The previous article introduced the usage of ecrecover, but the built-in ecrecover has a signature malleability problem. This article will explain this problem and how to solve it. ProblemExamples from the previous article: 1234567function test() external view returns(address) { bytes32 hash = 0xc1af4b94166cd32fc49b7b926cbb91ee421de2d04450e8ae57857b9b56ac7e53; uint8 v = 0x1b; bytes32 r = 0xe1077fb9321c187d8a43926896abac5455ce6add269e098f855ff059d6b846a3; bytes32 s = 0x56320be5f6d79c4d0e ...
Solidity - ecrecover
IntroductionThe ecrecover function in the smart contract can be used to verify the signature of the wallet. The verifier can confirm the identity of the signer without the signer’s private key. It is often used for off-chain authorization, and then used on-chain by a third party or for simple identity verification. Function1function ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address) hash: The hash of the signed message. v: v value of signature. r: r value of signature. s: ...
zkEVM Airdrop Guide
zkEVM is one of the L2 solutions of ZK Rollup. While there is already a MATIC coin, it is said that there may be an airdrop opportunity as well. Here I research and organize a piece of information for your reference. As the same L2 ZK Rollup solution, the strategy is the same as the previous zkSync Airdrop Strategy. WalletJust use Metamask. BridgezkEVM 的 Bridge page, it is better to bridge when fee is under $6 (0.0028 ETH). ApplicationList some applications that have been on the mainnet Name ...
Using Web3.js to Parse Custom Error
The previous article Solidity - Custom Error mentioned how to use custom error in smart contracts. This article continues this topic and explains how to use Web3.js to parse custom error when call, estimateGas and transaction failed. Web3.js version 4.0.1 is used here, tested at Arbitrum Goerli. Example ContractFirst, we prepare a contract as follows: 1234567891011121314151617181920error EmptyError();error ErrorWithArgs(address user);contract MyContract { function sendEmptyError() external ...
Using Ethers.js to Parse Custom Error
The previous article Solidity - Custom Error mentioned how to use custom error in smart contracts. This article continues this topic and explains how to use Ethers.js to parse custom error when call, estimateGas and transaction failed. Ethers.js version 6.5.1 is used here, tested at Arbitrum Goerli. Example ContractFirst, we prepare a contract as follows: 1234567891011121314151617181920error EmptyError();error ErrorWithArgs(address user);contract MyContract { function sendEmptyError() exte ...