Skip to content

Commit ead4e48

Browse files
committed
fix: sync lesson 4 content with code (MetaTransaction + HttpWrapper)
1 parent 28621bb commit ead4e48

File tree

1 file changed

+23
-21
lines changed
  • src/content/tutorial/6-gasless-transfers/4-static-relay

1 file changed

+23
-21
lines changed

src/content/tutorial/6-gasless-transfers/4-static-relay/content.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,42 +106,44 @@ const approvalAmount = amountToSend.add(staticFee)
106106

107107
## Step 4: Sign the USDT Meta-Approval
108108

109-
Build the EIP-712 payload and sign it with the sponsor wallet.
109+
USDT on Polygon uses `executeMetaTransaction` for gasless approvals. Build the EIP-712 MetaTransaction payload and sign it.
110110

111111
```js
112+
// First, encode the approve function call
113+
const approveFunctionSignature = usdt.interface.encodeFunctionData('approve', [
114+
TRANSFER_CONTRACT_ADDRESS,
115+
approvalAmount
116+
])
117+
118+
// Build the MetaTransaction EIP-712 domain
112119
const domain = {
113-
name: 'Tether USD',
120+
name: 'USDT0',
114121
version: '1',
115-
chainId: 137,
116-
verifyingContract: USDT_ADDRESS
122+
verifyingContract: USDT_ADDRESS,
123+
salt: ethers.utils.hexZeroPad(ethers.utils.hexlify(137), 32) // chainId as salt
117124
}
118125

119126
const types = {
120-
Permit: [
121-
{ name: 'owner', type: 'address' },
122-
{ name: 'spender', type: 'address' },
123-
{ name: 'value', type: 'uint256' },
127+
MetaTransaction: [
124128
{ name: 'nonce', type: 'uint256' },
125-
{ name: 'deadline', type: 'uint256' }
129+
{ name: 'from', type: 'address' },
130+
{ name: 'functionSignature', type: 'bytes' }
126131
]
127132
}
128133

129-
const deadline = Math.floor(Date.now() / 1000) + 3600 // 1 hour
130-
const value = {
131-
owner: wallet.address,
132-
spender: TRANSFER_CONTRACT_ADDRESS,
133-
value: approvalAmount,
134-
nonce,
135-
deadline
134+
const message = {
135+
nonce: nonce.toNumber(),
136+
from: wallet.address,
137+
functionSignature: approveFunctionSignature
136138
}
137139

138-
const signature = await wallet._signTypedData(domain, types, value)
140+
const signature = await wallet._signTypedData(domain, types, message)
139141
const { r, s, v } = ethers.utils.splitSignature(signature)
140142

141-
console.log('✍️ Approval signed')
143+
console.log('✍️ USDT approval signed')
142144
```
143145

144-
This approval allows the transfer contract to pull both the transfer amount and the relay fee from your wallet.
146+
This signature allows the relay to execute the `approve` call on your behalf via `executeMetaTransaction`.
145147

146148
---
147149

@@ -212,9 +214,9 @@ console.log('✍️ Relay request signed')
212214
Use the OpenGSN HTTP client to send the request to your chosen relay.
213215

214216
```js
215-
import { HttpClient } from '@opengsn/common/dist/HttpClient'
217+
import { HttpClient, HttpWrapper } from '@opengsn/common'
216218

217-
const httpClient = new HttpClient()
219+
const httpClient = new HttpClient(new HttpWrapper(), console)
218220
const relayResponse = await httpClient.relayTransaction(process.env.RELAY_URL, {
219221
relayRequest,
220222
metadata: {

0 commit comments

Comments
 (0)