Outdated doc and issue with transfer ERC20
Yo @alexanderatallah, it's me again from Cryptovoxels, I'm trying to set up an interface to transfer ERC20s using opensea-js.
I'm using this example from the documentation: Gifting erc tokens Especially, I'm using this example for my case:
To transfer fungible assets without token IDs, like ERC20 tokens, you can pass in an OpenSeaFungibleToken as the asset, set schemaName to "ERC20", and include quantity in base units (e.g. wei) to indicate how many.
Example for transfering 2 DAI ($2) to another address:
const paymentToken = (await seaport.api.getPaymentTokens({ symbol: 'DAI'}))[0]
const quantity = new BigNumber(Math.pow(10, paymentToken.decimals)).times(2)
const transactionHash = await seaport.transfer({
asset: {
tokenAddress: paymentToken.address,
schemaName: "ERC20"
},
fromAddress, // Must own the tokens
toAddress,
quantity
})
First off,
this seems outdated since paymentToken is an object with property tokens which is an Array,
so (await seaport.api.getPaymentTokens({ symbol: 'DAI'}))[0] should become await seaport.api.getPaymentTokens({ symbol: 'DAI'})
and paymentToken.decimals becomes paymentToken.tokens[0].decimals, the same applies to paymentToken.address.
Second,
I get a typescript error if I don't set tokenId in the asset object, so I write tokenId:null,, even though the example doesn't specify it.
Third,
I get a typescript error when writing schemaName: 'ERC20', so I changed that to schemaName: WyvernSchemaName.ERC20, .
In the end
I obtain the following code:
const paymentToken = await this.seaport.api.getPaymentTokens({ symbol })
const bigQuantity = new BigNumber(Math.pow(10, paymentToken.tokens[0].decimals)).times(2)
const transactionHash = await this.seaport.transfer({
asset: {
tokenId: null,
tokenAddress: paymentToken.tokens[0].address,
schemaName: WyvernSchemaName.ERC20,
},
fromAddress,
toAddress,
quantity: bigQuantity,
})
return transactionHash
However, this gives me the following error:
TypeError: Cannot read property 'Function' of undefined
at Object.exports.annotateERC20TransferABI (utils.js:107)
at OpenSeaPort.<anonymous> (seaport.js:1397)
at step (seaport.js:40)
at Object.next (seaport.js:21)
at seaport.js:15
at new Promise (<anonymous>)
at __awaiter (seaport.js:11)
at OpenSeaPort.transfer (seaport.js:1383)
Which according to the doc is linked to this line: https://github.com/ProjectOpenSea/opensea-js/blob/27299cd3aa71f918d219ce084c2aaade240163a1/src/utils/utils.ts#L105
Is there anything I'm missing or is it an actual bug?
Versions:
"opensea-js: "^1.1.10", "web3": "^0.20.7",
oof, we need to change the docs, will do that now!
In terms of the error you get: the only cause that I've seen for that has been multiple conflicting versions of web3 going on in the repo due to dependencies requesting different versions. The best way to fix this is to switch to yarn from npm. Are you using yarn?
Not really, and I've never used it 😖 Would it really be that? I find it weird that getting orders and fulfilling orders work perfectly while transferring ERC20 gives me an error...
If I do switch to yarn, how would you recommend doing it?
Right, ok @alexanderatallah , It can't be the version, cause npm ls web3 returns this

So no other version is being imported....
@DJViau anything?
Hi, I'm using Yarn but see the same error as above. My dep graph looks similar to the image above - [email protected]

oof, we need to change the docs, will do that now!
In terms of the error you get: the only cause that I've seen for that has been multiple conflicting versions of web3 going on in the repo due to dependencies requesting different versions. The best way to fix this is to switch to yarn from npm. Are you using yarn?
Can you upgrade web3 to 1.6.3? web3 0.20.7 is already 4 years ago
Docs have been upgraded, closing this issue out