Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
4
Indexable
Never
try {
        let provider = new ethers.providers.JsonRpcProvider("https://bsc-testnet.publicnode.com");
        const typedData = {
        types: {
            WithdrawRequest: [
                {name: "signer", type: "address"},
                {name: "token", type: "address"},
                {name: "receiver", type: "address"},
                {name: "amount", type: "uint256"},
                {name: "nonce", type: "uint256"},
                {name: "deadline", type: "uint256"},
            ],
        },
        primaryType: "WithdrawRequest",
        domain: {
            name: "Exchange",
            version: "1.0.0",
            chainId: 97,
            verifyingContract: "0x349d986890F457EB8AdCa3AbaEf7DE467B552873",
        },
        message: {
            signer: "0xfB6e22aA53c0804a522Eb40fB7A0b6F7140FD7f8",
            token: "0x110F1586329D01b6C12F30588C6F8EECa93132f2",
            receiver: "0x3f777FCF79EE4D9297b26660BA2593c906525504",
            amount: "1000000000000000",
            nonce: 1, // getNonce()
            deadline: 1687949677246,
        },
    };
    const signer = new ethers.Wallet("bdb1ddd8b1853884fd91a0a58e466ed7b91c480b557bd7ed3f57e30139b27a48", provider);

    signer._signTypedData(
        typedData.domain,
        typedData.types,
        typedData.message
    ).then(res => {
        console.log(res)
    });
} catch (error) {
    console.log(error);
}