Skip to content

Commit

Permalink
feat: fix transfer meta-tx (decentraland#458)
Browse files Browse the repository at this point in the history
* feat: fix transfer meta-tx

* chore: fix tests
  • Loading branch information
cazala authored Nov 11, 2021
1 parent 13f95f2 commit abc4f26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion webapp/src/modules/vendor/decentraland/NFTService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe("Decentraland's NFTService", () => {

it("should have called send transaction with the erc721's contract using the nft's chain id and contract address", async () => {
const contract: ContractData = {
...getContract(ContractName.ERC721, nft.chainId),
...getContract(ContractName.ERC721CollectionV2, nft.chainId),
address: nft.contractAddress
}
await nftService.transfer(wallet, anAddress, nft)
Expand Down
19 changes: 15 additions & 4 deletions webapp/src/modules/vendor/decentraland/NFTService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Network } from '@dcl/schemas'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils'
import {
Expand Down Expand Up @@ -60,10 +61,20 @@ export class NFTService
throw new Error('Invalid address. Wallet must be connected.')
}

const contract: ContractData = {
...getContract(ContractName.ERC721, nft.chainId),
address: nft.contractAddress
}
const contract: ContractData =
/* We need to use the ERC721CollectionV2 instead of ERC721 for non-ethereum transfers otherwise
the meta-tx would fail due to wrong domain and version.
If some day we have other types of NFTs other than ERC721CollectionV2 we will need to handle them appropiately too.
*/
nft.network !== Network.ETHEREUM
? {
...getContract(ContractName.ERC721CollectionV2, nft.chainId),
address: nft.contractAddress
}
: {
...getContract(ContractName.ERC721, nft.chainId),
address: nft.contractAddress
}

return sendTransaction(contract, erc721 =>
erc721.transferFrom(wallet.address, to, nft.tokenId)
Expand Down

0 comments on commit abc4f26

Please sign in to comment.