1
- import { ethers } from 'ethers'
1
+ import { ethers } from 'ethers' ;
2
2
3
3
/**
4
4
* Deploy the given contract
@@ -8,22 +8,22 @@ import { ethers } from 'ethers'
8
8
* @return {Contract } deployed contract
9
9
*/
10
10
export const deploy = async ( contractName : string , args : Array < any > , accountIndex ?: number ) : Promise < ethers . Contract > => {
11
+ console . log ( `deploying ${ contractName } ` )
11
12
12
- console . log ( `deploying ${ contractName } ` )
13
- // Note that the script needs the ABI which is generated from the compilation artifact.
14
- // Make sure contract is compiled and artifacts are generated
15
- const artifactsPath = `browser/contracts/artifacts/ ${ contractName } .json` // Change this for different path
13
+ // Note that the script needs the ABI which is generated from the compilation artifact.
14
+ // Make sure contract is compiled and artifacts are generated
15
+ const artifactsPath = `browser/contracts/artifacts/ ${ contractName } .json` // Change this for different path
16
+ const metadata = JSON . parse ( await remix . call ( 'fileManager' , 'getFile' , artifactsPath ) )
16
17
17
- const metadata = JSON . parse ( await remix . call ( 'fileManager' , 'getFile' , artifactsPath ) )
18
- // 'web3Provider' is a remix global variable object
18
+ // 'web3Provider' is a remix global variable object
19
+ const provider = new ethers . BrowserProvider ( web3Provider ) ;
20
+ const signer = await provider . getSigner ( accountIndex ) ;
19
21
20
- const signer = ( new ethers . providers . Web3Provider ( web3Provider ) ) . getSigner ( accountIndex )
22
+ const factory = new ethers . ContractFactory ( metadata . abi , metadata . data . bytecode . object , signer ) ;
23
+ const contract = await factory . deploy ( ...args ) ;
21
24
22
- const factory = new ethers . ContractFactory ( metadata . abi , metadata . data . bytecode . object , signer )
25
+ // The contract is NOT deployed yet; we must wait until it is mined
26
+ await contract . waitForDeployment ( ) ;
23
27
24
- const contract = await factory . deploy ( ...args )
25
-
26
- // The contract is NOT deployed yet; we must wait until it is mined
27
- await contract . deployed ( )
28
- return contract
29
- }
28
+ return contract ;
29
+ }
0 commit comments