Skip to content

Commit 534473c

Browse files
authored
Merge pull request #35 from tokenbound/bj/fp-60-enable-transfers-using-ens-addresses
Enable ENS transfers
2 parents 853ac68 + 3fd8401 commit 534473c

File tree

11 files changed

+232
-73
lines changed

11 files changed

+232
-73
lines changed

packages/sdk/src/TokenboundClient.ts

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ import {
5252
isEthers5SignableMessage,
5353
isEthers6SignableMessage,
5454
isViemSignableMessage,
55+
resolvePossibleENS,
5556
} from './utils'
56-
// import { normalize } from 'viem/ens'
5757

5858
class TokenboundClient {
5959
private chainId: number
@@ -384,30 +384,32 @@ class TokenboundClient {
384384

385385
const is1155: boolean = tokenType === NFTTokenType.ERC1155
386386

387-
// Configure required args based on token type
388-
const transferArgs: unknown[] = is1155
389-
? [
390-
// ERC1155: safeTransferFrom(address,address,uint256,uint256,bytes)
391-
tbAccountAddress,
392-
recipientAddress,
393-
tokenId,
394-
1,
395-
'0x',
396-
]
397-
: [
398-
// ERC721: safeTransferFrom(address,address,uint256)
399-
tbAccountAddress,
400-
recipientAddress,
401-
tokenId,
402-
]
403-
404-
const transferCallData = encodeFunctionData({
405-
abi: is1155 ? erc1155Abi : erc721Abi,
406-
functionName: 'safeTransferFrom',
407-
args: transferArgs,
408-
})
409-
410387
try {
388+
const recipient = await resolvePossibleENS(this.publicClient, recipientAddress)
389+
390+
// Configure required args based on token type
391+
const transferArgs: unknown[] = is1155
392+
? [
393+
// ERC1155: safeTransferFrom(address,address,uint256,uint256,bytes)
394+
tbAccountAddress,
395+
recipient,
396+
tokenId,
397+
1,
398+
'0x',
399+
]
400+
: [
401+
// ERC721: safeTransferFrom(address,address,uint256)
402+
tbAccountAddress,
403+
recipient,
404+
tokenId,
405+
]
406+
407+
const transferCallData = encodeFunctionData({
408+
abi: is1155 ? erc1155Abi : erc721Abi,
409+
functionName: 'safeTransferFrom',
410+
args: transferArgs,
411+
})
412+
411413
return await this.executeCall({
412414
account: tbAccountAddress,
413415
to: tokenContract,
@@ -429,21 +431,11 @@ class TokenboundClient {
429431
*/
430432
public async transferETH(params: ETHTransferParams): Promise<`0x${string}`> {
431433
const { account: tbAccountAddress, amount, recipientAddress } = params
432-
433434
const weiValue = parseUnits(`${amount}`, 18) // convert ETH to wei
434-
let recipient = getAddress(recipientAddress)
435-
436-
// @BJ todo: debug
437-
// const isENS = recipientAddress.endsWith(".eth")
438-
// if (isENS) {
439-
// recipient = await this.publicClient.getEnsResolver({name: normalize(recipientAddress)})
440-
// if (!recipient) {
441-
// throw new Error('Failed to resolve ENS address');
442-
// }
443-
// }
444-
// console.log('RECIPIENT_ADDRESS', recipient)
445435

446436
try {
437+
const recipient = await resolvePossibleENS(this.publicClient, recipientAddress)
438+
447439
return await this.executeCall({
448440
account: tbAccountAddress,
449441
to: recipient,
@@ -479,17 +471,14 @@ class TokenboundClient {
479471

480472
const amountBaseUnit = parseUnits(`${amount}`, erc20tokenDecimals)
481473

482-
// const recipient = recipientAddress.endsWith('.eth')
483-
// ? await this.publicClient.getEnsResolver({ name: normalize(recipientAddress) })
484-
// : recipientAddress
485-
486-
const callData = encodeFunctionData({
487-
abi: erc20Abi,
488-
functionName: 'transfer',
489-
args: [recipientAddress, amountBaseUnit],
490-
})
491-
492474
try {
475+
const recipient = await resolvePossibleENS(this.publicClient, recipientAddress)
476+
477+
const callData = encodeFunctionData({
478+
abi: erc20Abi,
479+
functionName: 'transfer',
480+
args: [recipient, amountBaseUnit],
481+
})
493482
return await this.executeCall({
494483
account: tbAccountAddress,
495484
to: erc20tokenAddress,

0 commit comments

Comments
 (0)