Skip to content

Lightweight library for signing ERC-2612 permit signatures.

Notifications You must be signed in to change notification settings

wildcards-world/eth-permit

 
 

Repository files navigation

eth-permit with two providers

This package simplifies the process of signing permit messages for Ethereum tokens. It adds a mechanism to provide two providers instead of one, to e.g. request the nonce and domain-parameters from one chain and retrieve the signature of the user while they are connected to another network.

What is permit?

Permit is a technique for metatransaction token transfers. Using permit can allow a contract to use a user's tokens without the user first needing to first to send an approve() transaction.

Permit variations

Permit was first introduced in the Multi-Collateral Dai token contract.

The permit technique is being standardized as part of ERC-2612. This standard (which has already been implemented in projects like Uniswap V2) is slightly different than the implementation used by Dai. Therefore, this library provides functions for signing both types of messages.

Usage

Install the package eth-permit using npm or yarn.

Dai-style permits

import { signDaiPermit } from 'eth-permit';

// Sign message using injected provider (ie Metamask).
// You can replace window.ethereum with any other web3 provider.
const result = await signDaiPermit(window.ethereum1, window.ethereum2, tokenAddress, senderAddress, spender);

await token.methods.permit(senderAddress, spender, result.nonce, result.expiry, true, result.v, result.r, result.s).send({
  from: senderAddress,
});

ERC2612-style permits

import { signERC2612Permit } from 'eth-permit';

const value = web3.utils.toWei('1', 'ether');

// Sign message using injected provider (ie Metamask).
// You can replace window.ethereum with any other web3 provider.
const result = await signERC2612Permit(window.ethereum1, window.ethereum2, tokenAddress, senderAddress, spender, value);

await token.methods.permit(senderAddress, spender, value, result.deadline, result.v, result.r, result.s).send({
  from: senderAddress,
});

About

Lightweight library for signing ERC-2612 permit signatures.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 93.7%
  • JavaScript 6.3%