How to get the second element of the array in a smart contract (params)?

Hello.

Docs:

params (optional): Parameters needed for your specific function

Contract:

address[] public users;

How to get user ID 1?

params: [1],

or

params: {args: [1]},

Please tell me, since this is not in the documentation. Or I overlooked.

what is the abi for that function?

	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"name": "users",
		"outputs": [
			{
				"internalType": "address",
				"name": "",
				"type": "address"
			}
		],
		"stateMutability": "view",
		"type": "function"
	}

and what is the connection with an array?

How to get second element of array using ethers.js?

	const daiContract = new ethers.Contract(
		address,
		abi,
		provider
	)
    daiContract.users(1)

How to get second element of array using react-moralis useApiContract?

array = function, but the parameters are unnamed

params - object, and requires specifying the name of the parameter

you can change the abi and give those parameters a name, that requires no change at contract level

1 Like

Wow, cheat code :laughing:
Thanks.

	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "cheatId",
				"type": "uint256"
			}
		],
		"name": "users",
		"outputs": [
			{
				"internalType": "address",
				"name": "",
				"type": "address"
			}
		],
		"stateMutability": "view",
		"type": "function"
	}

use

params: {cheatId: "1"},
1 Like