Types of property 'stateMutability' are incompatible.
Type 'string' is not assignable to type '"view" | "nonpayable" | "pure" | "payable" | undefined'
Error when building contract object
abi
"stateMutability": "view",
"stateMutability": "nonpayable",
"stateMutability": "pure",
@xumoyan Thanks for opening this issue! Could you please follow the issue template we provide with all the required points?
just getting in touch with eth
i referenced the wrong dependency library
thank you for your answer
Is this not still an issue, unless I am missing something:
Example:
"web3": "^1.2.6"
export const CPRABI = [
{
constant: true,
inputs: [],
name: 'lastPoolId',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
name: 'poolOwners',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
name: 'pools',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: false,
inputs: [],
name: 'createNewPool',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
payable: true,
stateMutability: 'payable',
type: 'function',
},
]
const web3 = new Web3(Web3.givenProvider)
const addr = '0x96fF7e5667dE8Bc4856F09dbe509eE4623611487'
const cpr = new web3.eth.Contract(CPRABI, addr)
Argument of type '{ constant: boolean; inputs: { internalType: string; name: string; type: string; }[]; name: string; outputs: { internalType: string; name: string; type: string; }[]; payable: boolean; stateMutability: string; type: string; }[]' is not assignable to parameter of type 'AbiItem | AbiItem[]'.
Type '{ constant: boolean; inputs: { internalType: string; name: string; type: string; }[]; name: string; outputs: { internalType: string; name: string; type: string; }[]; payable: boolean; stateMutability: string; type: string; }[]' is not assignable to type 'AbiItem[]'.
Type '{ constant: boolean; inputs: { internalType: string; name: string; type: string; }[]; name: string; outputs: { internalType: string; name: string; type: string; }[]; payable: boolean; stateMutability: string; type: string; }' is not assignable to type 'AbiItem'.
Types of property 'stateMutability' are incompatible.
Type 'string' is not assignable to type '"view" | "payable" | "pure" | "nonpayable" | undefined'. TS2345
47 | const web3 = new Web3(Web3.givenProvider)
48 | const addr = '0x96fF7e5667dE8Bc4856F09dbe509eE4623611487'
> 49 | const cpr = new web3.eth.Contract(CPRABI, addr)
| ^
50 |
51 | export const App: FC = () => {
52 | const routes = routeConfig.map((props) => {
Totally still an issue.
Also getting:
Types of property 'stateMutability' are incompatible.
Type 'string' is not assignable to type '"view" | "payable" | "pure" | "nonpayable" | undefined'. TS2345
Hey @tsujp, also had the same issue but it's not related to web3.
The stateMutability is correctly an enum and your abi is correct as well, the issue derives from the way import and require() work. Since you're using React from what I see, I believe you used import.
Try:
import Web3 from 'web3';
const CPRABI = require('./token');
const web3 = new Web3(Web3.givenProvider)
const addr = '0x96fF7e5667dE8Bc4856F09dbe509eE4623611487'
const cpr = new web3.eth.Contract(CPRABI, addr)
Enjoy :)
Most helpful comment
Is this not still an issue, unless I am missing something:
Example: