Getting error "... is not a function" for Write Methods
See original GitHub issueI am using ethers.js
in hardhat (buidler) testing and cannot call Write Methods. I can access contracts Properties and Read-Only Methods, but when I call Write Methods I keep getting "... is not a function"
error:
In my sample is an ERC20 Token. I can see the method also when calling contract.interface
:
const { expect } = require("chai");
describe("Test", function () {
let FZBAT, AddressProvider, ZBAT, owner, addr1, addr2;
const mintAmount = (50 * (10 ** 18)).toString(); // 50 Tokens
before(async function () {
const FZBATArt = await ethers.getContractFactory("FZBAT");
FZBAT = await upgrades.deployProxy(FZBATArt, ["FZBAT", "FZ BA Token", 16]);
await FZBAT.deployed();
console.log('vDeployed FZBAT', FZBAT.address);
});
it("Should mint tokens from FZBAT", async () => {
let result = await FZBAT.mint(addr1.address, mintAmount);
});
});
console:
Test
vDeployed FZBAT 0xCBF508609D841D2dA4E31cFAA504e2922e625e31
1) Should mint tokens from FZBAT
0 passing (5s)
1 failing
1) Test
Should mint tokens from FZBAT:
TypeError: FZBAT.mint is not a function
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >How to Handle JavaScript Uncaught TypeError: “x” is Not a ...
The Javascript error TypeError: "x" is not a function occurs when there is an attempt to call a function on a value or...
Read more >JavaScript error: "is not a function" - Stack Overflow
It was attempted to call a value like a function, but the value is not actually a function. Some code expects you to...
Read more >JavaScript: Uncaught TypeError: n is not a function
Uncaught TypeError : 'n' is not a function: This is a standard JavaScript error when trying to call a function before it is...
Read more >How to solve the "is not a function" error in JavaScript
How to solve the "is not a function" error in JavaScript. Published in 2020 ... I write JavaScript without semicolons. ... Let's look...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you have two methods with the same name, you must specify the fully qualified signature to access it. You can use either of the following, depending on which you want:
If you only use one of those methods, you can simply drop the unused one from the ABI you pass into the Contract constructor, then you can use the name
mint
to access it.For more details, see https://github.com/ethers-io/ethers.js/issues/950#issuecomment-657803378. 😃
@SvenMeyer
If the result is ambiguous, you must specify the signature. It is not, in general, safe to simply use the “first” one, since various compilers, versions and tools manipulate and output the ABI in different orders. Orders could be alphabetical, ordered by the selector, argument count, dependency order, etc. You won’t want switching the compiler version to cause your JavaScript to break. 😃
In general I highly recommend that people only include the fragments they use, and to use the Human-Readable ABI (which is much smaller than the equivalent JSON). If there is a method that is completely unused, excluding it keeps the code cleaner and the bundle size smaller. An ABI can easily be 10kb-500kb, while most things only require 1-10 signatures, which fits in about 50-600 bytes. 😃
Does that make sense?