Skip to content

Instantly share code, notes, and snippets.

View danielnordh's full-sized avatar

Daniel Nordh danielnordh

View GitHub Profile
@danielnordh
danielnordh / usdc_permit.js
Created January 30, 2024 11:26
USDC Permit fails with invalid signature on Polygon
var web3 = require("web3");
const ethSigUtil = require("@metamask/eth-sig-util");
const { SignTypedDataVersion } = require("@metamask/eth-sig-util");
const ethUtil = require("ethereumjs-util");
async function permit(_web3, _USDCInstance) {
const usdcAddress = "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359";
const privateKey = "..."; // owner's pk
const pkBuffer = Buffer.from(privateKey, "hex");
@danielnordh
danielnordh / USDC_Polygon.dart
Last active May 12, 2022 15:18
USDC transferWithAuthorization works on Ropsten but fails on Polygon
final msgParams = {
"types": {
"EIP712Domain": [
{"type": "string", "name": "name"},
{"type": "string", "name": "version"},
{"type": "uint256", "name": "chainId"},
{"type": "address", "name": "verifyingContract"}
],
"TransferWithAuthorization": [
{"name": "from", "type": "address"},
@danielnordh
danielnordh / gist:d0e174b66ebd3af6ddbf07b48a91813b
Last active March 25, 2022 09:03
USDC transferWithAuthorization call failing on zkSync, but working on Ropsten
// See comment below with code example
@danielnordh
danielnordh / gist:b546adcebc7f560e4ad899f399370551
Last active March 5, 2023 19:14
EIP712 sign a USDC transferWithAuthorization tx on a dart client, for broadcasting from server (WIP)
Future<String?> signUSDC(
BigInt amount, Web3Dart.EthereumAddress ethAddress, User user) async {
final config = ref.read(configurationProvider).instance;
final wallet = Web3Dart.Wallet.fromJson(user.ethereumWallet!, kWalletPassword);
final validAfter = BigInt.zero;
final validBefore = BigInt.from(9223372036854775807);
final nonce = Nonce.secure(32);
final nonceBytes = utf8.encode(nonce.toString());