ethers.js
ethers.js copied to clipboard
ether.js error: Assignment to constant variable
Ethers Version
5.6.7
Search Terms
No response
Describe the Problem
I import ether.js with vue , connect user’s wallert , init smart contract which was deployed in rinkeby network, then trigger function.
It’s work successfully when I run with node and not build the project. When I run 'npm run build’ and deploy the online website, error has occurred. Error message is 'Assignment to constant variable’.
when i debug this error, the browser breakpoint shows that there is a problem with this part this.resolvedAddress.catch((e) => { }); const uniqueNames = {}; const uniqueSignatures = {}; Object.keys(this.interface.functions).forEach((signature) => { const fragment = this.interface.functions[signature]; // Check that the signature is unique; if not the ABI generation has // not been cleaned or may be incorrectly generated if (uniqueSignatures[signature]) { logger.warn(
Duplicate ABI entry for ${JSON.stringify(signature)}); return; } uniqueSignatures[signature] = true; // Track unique names; we only expose bare named functions if they // are ambiguous { const name = fragment.name; if (!uniqueNames[
%${name}]) { uniqueNames[
%${name}] = []; } uniqueNames[
%${name}].push(signature); } if (this[signature] == null) { defineReadOnly(this, signature, buildDefault(this, fragment, true)); } // We do not collapse simple calls on this bucket, which allows // frameworks to safely use this without introspection as well as // allows decoding error recovery. if (this.functions[signature] == null) { defineReadOnly(this.functions, signature, buildDefault(this, fragment, false)); } if (this.callStatic[signature] == null) { defineReadOnly(this.callStatic, signature, buildCall(this, fragment, true)); } if (this.populateTransaction[signature] == null) { defineReadOnly(this.populateTransaction, signature, buildPopulate(this, fragment)); } if (this.estimateGas[signature] == null) { defineReadOnly(this.estimateGas, signature, buildEstimate(this, fragment)); } });
Code Snippet
async whiteListMintFunc() {
let abi = [
'function whitelistMint(address _account, uint _quantity, bytes32[] _proof) public payable'
];
let provider = new ethers.providers.Web3Provider(window.ethereum);
let signer = provider.getSigner();
// error seems like occurred the next line
let contract = new ethers.Contract(
this.contractAddress,
abi,
signer
);
let etherNumber = 0.0045 * this.currentQuantity;
let overrides = {
value: ethers.utils.parseEther(etherNumber.toString())
};
await contract.whitelistMint(
this.currentAccount,
this.currentQuantity,
this.accountProof,
overrides
).then(res => {
}).catch(err => {
});
}
Contract ABI
[
'function whitelistMint(address _account, uint _quantity, bytes32[] _proof) public payable'
]
Errors
Uncaught (in promise) TypeError: Assignment to constant variable.
at index.js:215:1
at Array.forEach (<anonymous>)
at new gn (index.js:551:1)
at new bn (index.js:896:1)
at o.<anonymous> (time-line.vue:135:1)
at z (runtime.js:62:15)
at Generator._invoke (runtime.js:296:1)
at Generator.t.<computed> [as next] (runtime.js:114:1)
at n (asyncToGenerator.js:17:1)
at asyncToGenerator.js:35:1
Environment
node.js (v12 or newer)
Environment (Other)
No response
I don't think this can be an issue necessarily with ethers; does Vue use some sort of compilation or transpiring step, like using Babel?
The TypeScript compiler should find any instance of a const variable being re-assigned.
have you fixed this problem
this troble me the same. when i npm run dev is ok on my local. but when i npm run build deploy to the website then is broken
this troble me the same. when i npm run dev is ok on my local. but when i npm run build deploy to the website then is broken
delete uglifyjs,will ok.