Factory file fails to compile when type `uint256[]` is used in the constructor
See original GitHub issueThe generated ConstructorWithIntArrayFactory.ts
file for the following Solidity will fail to compile as the BigNumberish
type is not imported from ethers/utils
contract ConstructorWithIntArray {
uint256[] someArray;
constructor(uint256[] memory _someArray) public {
someArray = _someArray;
}
}
The generated ConstructorWithIntArrayFactory.ts
file is
/* Generated by ts-generator ver. 0.0.8 */
/* tslint:disable */
import { Contract, ContractFactory, Signer } from "ethers";
import { Provider } from "ethers/providers";
import { UnsignedTransaction } from "ethers/utils/transaction";
import { ConstructorWithIntArray } from "./ConstructorWithIntArray";
export class ConstructorWithIntArrayFactory extends ContractFactory {
constructor(signer?: Signer) {
super(_abi, _bytecode, signer);
}
deploy(_someArray: (BigNumberish)[]): Promise<ConstructorWithIntArray> {
return super.deploy(_someArray) as Promise<ConstructorWithIntArray>;
}
getDeployTransaction(_someArray: (BigNumberish)[]): UnsignedTransaction {
return super.getDeployTransaction(_someArray);
}
attach(address: string): ConstructorWithIntArray {
return super.attach(address) as ConstructorWithIntArray;
}
connect(signer: Signer): ConstructorWithIntArrayFactory {
return super.connect(signer) as ConstructorWithIntArrayFactory;
}
static connect(
address: string,
signerOrProvider: Signer | Provider
): ConstructorWithIntArray {
return new Contract(
address,
_abi,
signerOrProvider
) as ConstructorWithIntArray;
}
}
const _abi = [
{
inputs: [
{
internalType: "uint256[]",
name: "_someArray",
type: "uint256[]"
}
],
payable: false,
stateMutability: "nonpayable",
type: "constructor"
}
];
const _bytecode =
"0x608060405234801561001057600080fd5b5060405161018f38038061018f8339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825186602082028301116401000000008211171561008557600080fd5b82525081516020918201928201910280838360005b838110156100b257818101518382015260200161009a565b5050505091909101604052505082516100d492506000915060208401906100db565b5050610143565b828054828255906000526020600020908101928215610116579160200282015b828111156101165782518255916020019190600101906100fb565b50610122929150610126565b5090565b61014091905b80821115610122576000815560010161012c565b90565b603e806101516000396000f3fe6080604052600080fdfea265627a7a72315820311701576656af678908509fac0c466c381c9bd65f0f04fa674cdf92fb1ab24c64736f6c634300050b0032";
The typescript errors are
Error:(14, 23) TS2304: Cannot find name 'BigNumberish'.
Error:(17, 37) TS2304: Cannot find name 'BigNumberish'.
The workaround is to include a dummy constructor parameter of type uint256
so the BigNumberish
type is imported in the factory type definition file.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Factory file fails to compile when type `uint256[]` is used in the ...
The generated ConstructorWithIntArrayFactory.ts file for the following Solidity will fail to compile as the BigNumberish type is not ...
Read more >trying to make my own token . But i am getting an error while ...
... to make my own token . But i am getting an error while compiling ... Type uint256 is not implicitly convertible to...
Read more >Warning: source file does not specify required compiler ...
computer: Environment I'm testing a Factory contract from uniswap in remix. :memo:Details nothing was done but copy the contract code from ...
Read more >solidity - Factory error The called function should be payable
I am using the Opensea Creatures repository (https://github.com/ProjectOpenSea/opensea-creatures.git) to make a Factory and create my ERC721 ...
Read more >Documentation - ethers
The network and apiKey are specified the same as the constructor. Note: Default API keys. If no apiKey is provided, a shared API...
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
Actually, this should be a bit better, and not too complicated:
/\WBigNumberish(\W|$)/
It should exclude all sane false positives whereBigNumberish
is found in the arg name, but not in the types – see last example here: https://regex101.com/r/WeFMHp/2The problem is with this line in the Ethers generator https://github.com/ethereum-ts/TypeChain/blob/master/lib/targets/ethers/generation.ts#L84
For the above example, the
constructorArgs
will have value_someArray: (BigNumberish)[],
which will not match/: BigNumberish/
. I’d suggest just matching on/BigNumberish/
as the BigNumberish could be in a multidimensional array or a struct.I was going to raise a PR but I can’t get the tests to work before I do my change.