0

I am trying to buy an NFT on OpenSea, when executing the fulfillOrder() method, I get an error saying The requested acconut has not been authorized by the user.

This is my code where I initialize the web3 provider and stuff:

this.web3 = new Web3(this.magic.rpcProvider);

const provider = new ethers.providers.Web3Provider(
    window.ethereum,
    "goerli"
);
this.seaport = new Seaport(provider);

Here is the code to buy the NFT:

const { executeAllActions } = await seaport.createOrder(
    {
      offer: [
        {
          amount: parseEther("0.27").toString(),
          // WETH on goerli
          token: "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
        },
      ],
      consideration: [
        {
          itemType: ItemType.ERC1155,
          token: contractAddress,
          identifier: tokenId,
          recipient: walletAddress,
        },
      ],
    },
    walletAddress
  );
  const order = await executeAllActions();

  const { executeAllActions: executeAllFulfillActions } =
    await seaport.fulfillOrder({
      order,
      accountAddress: "0x4b865b674e7a2258569f9275a48d0cb18e021588",
    });

  const transaction = executeAllFulfillActions();
  console.log(transaction, "transaction");

The createOrder() makes me sign with my wallet, and I even get all the way to the console log at the bottom and it does in fact log the transaction. But then Metamask throws this error: enter image description here

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
toekneema
  • 137
  • 1
  • 2
  • 7

2 Answers2

0

you did not call eth_requestAccounts rpc method. From docs

Under the hood, it calls wallet_requestPermissions for the eth_accounts permission. Since eth_accounts is currently the only permission, this method is all you need for now.

you should first have called:

 await ethereum.request({
    method: 'eth_requestAccounts',
  });
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
  • unfortunately this did not help. i called this `eth_requestAccounts` before the `seaport.createOrder()`, and still getting the same error – toekneema Mar 27 '23 at 05:42
  • also i've verified that my metamask is connected to this site (localhost:3000), so not sure why i'm still getting this error – toekneema Mar 27 '23 at 05:55
0

First need to requestAccount permission:

async function requestAccount() {
  try {
    const accounts = await window.ethereum.request({
      method: 'eth_requestAccounts',
    });
    return accounts[0];
  } catch (error) {
    console.error('User denied account access');
    return null;
  }
}

Call the requestAccount function and use the returned account address in your code:

const accountAddress = await requestAccount();
if (!accountAddress) {
  // Handle the case when the user denies account access.
}

Update your seaport.fulfillOrder() call:

const { executeAllActions: executeAllFulfillActions } =
  await seaport.fulfillOrder({
    order,
    accountAddress: accountAddress,
  });