Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't define array index property past the end of an array #3765

Closed
mktcode opened this issue Feb 11, 2023 · 2 comments
Closed

Can't define array index property past the end of an array #3765

mktcode opened this issue Feb 11, 2023 · 2 comments
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@mktcode
Copy link

mktcode commented Feb 11, 2023

Ethers Version

6.0.2

Search Terms

define array index property past the end of an array

Describe the Problem

When the event triggers:

image

When going back to 5.7.2 it works.

Code Snippet

async function mintNft() {
  const coords = {
    x: '1',
    y: '2',
    z: '3',
  };

  let signer = null;
  let provider;
  if (window.ethereum == null) {
    console.log("MetaMask not installed.");
    return;
  }
  provider = new ethers.BrowserProvider(window.ethereum);
  signer = await provider.getSigner();

  const contract = new Contract(import.meta.env.VITE_DGAME_CONTRACT_ADDRESS, DGAME_ABI, signer);

  contract.on("Transfer", (_from, to, tokenId, event) => {
    console.log(`Minted NFT ${tokenId} to ${to}`);

    event.removeListener();
  });

  const tx = await contract.safeMint(coords.x, coords.y, coords.z);
  await tx.wait();
}

Contract ABI

[
	{
		"inputs": [],
		"stateMutability": "nonpayable",
		"type": "constructor"
	},
	{
		"anonymous": false,
		"inputs": [
			{
				"indexed": true,
				"internalType": "address",
				"name": "owner",
				"type": "address"
			},
			{
				"indexed": true,
				"internalType": "address",
				"name": "approved",
				"type": "address"
			},
			{
				"indexed": true,
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "Approval",
		"type": "event"
	},
	{
		"anonymous": false,
		"inputs": [
			{
				"indexed": true,
				"internalType": "address",
				"name": "owner",
				"type": "address"
			},
			{
				"indexed": true,
				"internalType": "address",
				"name": "operator",
				"type": "address"
			},
			{
				"indexed": false,
				"internalType": "bool",
				"name": "approved",
				"type": "bool"
			}
		],
		"name": "ApprovalForAll",
		"type": "event"
	},
	{
		"anonymous": false,
		"inputs": [
			{
				"indexed": true,
				"internalType": "address",
				"name": "from",
				"type": "address"
			},
			{
				"indexed": true,
				"internalType": "address",
				"name": "to",
				"type": "address"
			},
			{
				"indexed": true,
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "Transfer",
		"type": "event"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "to",
				"type": "address"
			},
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "approve",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "owner",
				"type": "address"
			}
		],
		"name": "balanceOf",
		"outputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "burn",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"name": "coordinatesByTokenId",
		"outputs": [
			{
				"internalType": "int256",
				"name": "x",
				"type": "int256"
			},
			{
				"internalType": "int256",
				"name": "y",
				"type": "int256"
			},
			{
				"internalType": "int256",
				"name": "z",
				"type": "int256"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "getApproved",
		"outputs": [
			{
				"internalType": "address",
				"name": "",
				"type": "address"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "owner",
				"type": "address"
			},
			{
				"internalType": "address",
				"name": "operator",
				"type": "address"
			}
		],
		"name": "isApprovedForAll",
		"outputs": [
			{
				"internalType": "bool",
				"name": "",
				"type": "bool"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [],
		"name": "name",
		"outputs": [
			{
				"internalType": "string",
				"name": "",
				"type": "string"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "ownerOf",
		"outputs": [
			{
				"internalType": "address",
				"name": "",
				"type": "address"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "int256",
				"name": "x",
				"type": "int256"
			},
			{
				"internalType": "int256",
				"name": "y",
				"type": "int256"
			},
			{
				"internalType": "int256",
				"name": "z",
				"type": "int256"
			}
		],
		"name": "safeMint",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "from",
				"type": "address"
			},
			{
				"internalType": "address",
				"name": "to",
				"type": "address"
			},
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "safeTransferFrom",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "from",
				"type": "address"
			},
			{
				"internalType": "address",
				"name": "to",
				"type": "address"
			},
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			},
			{
				"internalType": "bytes",
				"name": "data",
				"type": "bytes"
			}
		],
		"name": "safeTransferFrom",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "operator",
				"type": "address"
			},
			{
				"internalType": "bool",
				"name": "approved",
				"type": "bool"
			}
		],
		"name": "setApprovalForAll",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "bytes4",
				"name": "interfaceId",
				"type": "bytes4"
			}
		],
		"name": "supportsInterface",
		"outputs": [
			{
				"internalType": "bool",
				"name": "",
				"type": "bool"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [],
		"name": "symbol",
		"outputs": [
			{
				"internalType": "string",
				"name": "",
				"type": "string"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "int256",
				"name": "",
				"type": "int256"
			},
			{
				"internalType": "int256",
				"name": "",
				"type": "int256"
			},
			{
				"internalType": "int256",
				"name": "",
				"type": "int256"
			}
		],
		"name": "tokenIdsByCoordinate",
		"outputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "tokenURI",
		"outputs": [
			{
				"internalType": "string",
				"name": "",
				"type": "string"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "from",
				"type": "address"
			},
			{
				"internalType": "address",
				"name": "to",
				"type": "address"
			},
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			}
		],
		"name": "transferFrom",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			},
			{
				"internalType": "string",
				"name": "uri",
				"type": "string"
			}
		],
		"name": "updateUri",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	}
]

Errors

Uncaught (in promise) TypeError: can't define array index property past the end of an array with non-writable length
    get abstract-coder.ts:118
    listeners contract.ts:591
    _emit contract.ts:588
    emit contract.ts:606
    listener contract.ts:543
    listeners abstract-provider.ts:1174
    emit abstract-provider.ts:1171
    _emitResults subscriber-filterid.ts:146
    poll_fn3 subscriber-filterid.ts:82
    listeners abstract-provider.ts:1174
    emit abstract-provider.ts:1171
    poll_fn subscriber-polling.ts:66
    func abstract-provider.ts:1062
    setTimeout handler*_setTimeout abstract-provider.ts:1068
    poll_fn subscriber-polling.ts:75
    func abstract-provider.ts:1062
    setTimeout handler*_setTimeout abstract-provider.ts:1068
    poll_fn subscriber-polling.ts:75
    func abstract-provider.ts:1062
    setTimeout handler*_setTimeout abstract-provider.ts:1068
    poll_fn subscriber-polling.ts:75
abstract-coder.ts:118:41
    emit contract.ts:609
    AsyncFunctionThrow self-hosted:811
    (Async: async)
    listener contract.ts:543
    listeners abstract-provider.ts:1174
    filter self-hosted:241
    emit abstract-provider.ts:1171
    AsyncFunctionNext self-hosted:807
    (Async: async)
    _emitResults subscriber-filterid.ts:146
    poll_fn3 subscriber-filterid.ts:82
    InterpretGeneratorResume self-hosted:1819
    AsyncFunctionNext self-hosted:807
    (Async: async)
    poll_fn3 self-hosted:1356
    listeners abstract-provider.ts:1174
    filter self-hosted:241
    emit abstract-provider.ts:1171
    AsyncFunctionNext self-hosted:807
    (Async: async)
    poll_fn subscriber-polling.ts:66
    AsyncFunctionNext self-hosted:807
    (Async: async)
    poll_fn self-hosted:1356
    func abstract-provider.ts:1062
    (Async: setTimeout handler)
    _setTimeout abstract-provider.ts:1068
    poll_fn subscriber-polling.ts:75
    AsyncFunctionNext self-hosted:807
    (Async: async)
    poll_fn self-hosted:1356
    func abstract-provider.ts:1062
    (Async: setTimeout handler)
    _setTimeout abstract-provider.ts:1068
    poll_fn subscriber-polling.ts:75
    AsyncFunctionNext self-hosted:807
    (Async: async)
    poll_fn self-hosted:1356
    func abstract-provider.ts:1062
    (Async: setTimeout handler)
    _setTimeout abstract-provider.ts:1068
    poll_fn subscriber-polling.ts:75


### Environment

Ethereum (mainnet/ropsten/rinkeby/goerli), node.js (v12 or newer), Browser (Chrome, Safari, etc)

### Environment (Other)

Vue3
@mktcode mktcode added the investigate Under investigation and may be a bug. label Feb 11, 2023
@ricmoo ricmoo added bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. v6 Issues regarding v6 and removed investigate Under investigation and may be a bug. labels Feb 13, 2023
@ricmoo
Copy link
Member

ricmoo commented Feb 13, 2023

This should be fixed now. Let me know if you still have any issues.

Thanks! :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Feb 13, 2023
@mktcode
Copy link
Author

mktcode commented Feb 13, 2023

Looks good! :)

@mktcode mktcode closed this as completed Feb 13, 2023
@mktcode mktcode changed the title Bug Report Title Can't define array index property past the end of an array Feb 18, 2023
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants