ProjectOpenSea / opensea-js

TypeScript SDK for the OpenSea marketplace
https://docs.opensea.io/reference
MIT License
2.28k stars 957 forks source link

createBuyOrder gives TypeError: Cannot read property 'id' of undefined #24

Closed carver closed 2 years ago

carver commented 5 years ago

I am trying to write a node.js script to place a buy order on a token. When I run it, I get:

$ node -r esm make-bid.js 
DEPRECATION NOTICE: Use `asset` instead of `tokenAddress`
TypeError: Cannot read property 'id' of undefined
    at IpcProvider._addResponseCallback (/home/jcarver/code/opensea-ens/node_modules/web3-providers-ipc/src/index.js:176:39)
    at IpcProvider.send (/home/jcarver/code/opensea-ens/node_modules/web3-providers-ipc/src/index.js:214:10)
    at /home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:437:99
    at /home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:140:28
    at new Promise (<anonymous>)
    at /home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:139:35
    at step (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:40:23)
    at Object.next (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:21:53)
    at /home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:15:71
    at new Promise (<anonymous>)
    at __awaiter (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:11:12)
    at promisify (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:137:12)
    at Object.<anonymous> (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:437:46)
    at step (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:40:23)
    at Object.next (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:21:53)
    at /home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/utils.js:15:71
(node:14571) UnhandledPromiseRejectionWarning: Error: You declined to authorize your offer
    at OpenSeaPort.<anonymous> (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/seaport.js:577:31)
    at step (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/seaport.js:40:23)
    at Object.throw (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/seaport.js:21:53)
    at rejected (/home/jcarver/code/opensea-ens/node_modules/opensea-js/lib/seaport.js:13:65)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)

Here is the code that is trying to place the offer:

// From https://github.com/ProjectOpenSea/opensea-js#getting-started

import * as Web3 from 'web3'
import { OpenSeaPort, Network } from 'opensea-js'

// This connects to a geth instance that has accountAddress unlocked
const provider = new Web3.providers.IpcProvider('/home/jcarver/.ethereum/geth.ipc', require('net'));

// *************************
// Making an offer, from https://github.com/ProjectOpenSea/opensea-js#making-offers

// Token ID and smart contract address for a non-fungible token:
const tokenId = 'XXXXXXXXXX';
const tokenAddress = '0xfac7bea255a6990f749363002136af6556b31e04';

// The offerer's wallet address:
const accountAddress = "0xZZZZZZZZZZZZZZZZ";

const seaport = new OpenSeaPort(provider, {
  networkName: Network.Main
})

async function makeBid() {
  const offer = await seaport.createBuyOrder({
    tokenId,
    tokenAddress,
    accountAddress,
    // Value of the offer, in units of the payment token (or wrapped ETH if none is specified):
    startAmount: 0.025,
  })
}

makeBid().then(console.log).catch(console.log);                

If the token ID and account address are important, I am happy to side-channel them. (I'm on the Discord server)

I know that the account is unlocked and connected correctly, because if I run this I see a signed message:

var W3 = require('web3');
const w3 = new W3(provider);
w3.eth.sign('message to sign', accountAddress).then(console.log)

Some environment info:

$ cat package.json 
{
  "name": "ens-bidder",
  "dependencies": {
    "esm": "^3.2.25",
    "opensea-js": "^0.6.3",
    "scrypt": "^6.0.3",
    "web3": "^1.2.1",
  }
}
$ node --version
v8.11.4
carver commented 5 years ago

I got some advice in Discord to update:

  const offer = await seaport.createBuyOrder({
    tokenId,
    tokenAddress,
    accountAddress,

to:

  const offer = await seaport.createBuyOrder({
    asset: {
      tokenId,
      tokenAddress
    },
    accountAddress,

But I'm seeing the same console error

alexanderatallah commented 5 years ago

@carver I think this is an issue with persona_sign in your provider. the command-line tooling for signing is extremely primitive and fragile right now. I recommend using

const MnemonicWalletSubprovider = require('@0x/subproviders').MnemonicWalletSubprovider
const RPCSubprovider = require('web3-provider-engine/subproviders/rpc')
const Web3ProviderEngine = require('web3-provider-engine')

See https://github.com/ProjectOpenSea/opensea-creatures/blob/master/scripts/sell.js

carver commented 5 years ago

So I'm a little hard-headed and really wanted the IPC version to work. Eventually, I was able to add an id to the outbound request, and it looks like that worked. (The only quirk being that the taker on the bid is set to 0x0000..., but the bid is showing up fine in the UI).

I'll leave this open. It would be nice for the library to work with accounts in local nodes like geth. If you want I can come back after Devcon and open a PR.

alexanderatallah commented 5 years ago

a taker of 0x0000... means that anyone can accept it, so that's fine. what do you mean about adding an id? which request, the eth rpc request? would your PR be on opensea-js or on Web3? currently we do

web3.currentProvider.sendAsync({
      method: 'personal_sign',
      params: [message, signerAddress],
      from: signerAddress,
    })

to do signatures, which is missing these params in the typescript lib:

id: number;
jsonrpc: string;

could that be the issue?

carver commented 5 years ago

would your PR be on opensea-js or on Web3?

It would be on opensea-js

currently we do

web3.currentProvider.sendAsync({
      method: 'personal_sign',
      params: [message, signerAddress],
      from: signerAddress,
    })

to do signatures, which is missing these params in the typescript lib:

id: number;
jsonrpc: string;

could that be the issue?

Yup, exactly. I added an id value to that message (I just hacked it into the installed opensea-js node module :see_no_evil: ), and that fixed the error message in the title.

alexanderatallah commented 5 years ago

@carver great, will fix that in the next version, coming this week

acechauminh commented 2 years ago
  1. Open file node_modules/opensea-js/lib/utils/utils.js.

  2. change web3.currentProvider.sendAsync to window.web3.currentProvider.sendAsync.

  3. restart app

hope can help