Skip to content

Commit 28d81d1

Browse files
committed
add remix config file
1 parent 271fab2 commit 28d81d1

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"defaultConfig": "ethers6",
3+
"customConfig": {
4+
"baseConfiguration": "default",
5+
"dependencies": []
6+
}
7+
}

libs/remix-ws-templates/src/templates/introToEIP7702/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default async (opts) => {
1313
// @ts-ignore
1414
'scripts/run-eip7702.ts': (await import('!!raw-loader!./scripts/run-eip7702.ts')).default,
1515
// @ts-ignore
16-
'README.md': (await import('raw-loader!./README.md')).default
16+
'README.md': (await import('raw-loader!./README.md')).default,
17+
// @ts-ignore
18+
'.remix/script.config.json': (await import('!!raw-loader!./.remix/script.config.json')).default
1719
}
1820
return filesObj
1921
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ethers } from 'ethers'
1+
import { ethers } from 'ethers';
22

33
/**
44
* Deploy the given contract
@@ -8,22 +8,22 @@ import { ethers } from 'ethers'
88
* @return {Contract} deployed contract
99
*/
1010
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
11-
1211
console.log(`deploying ${contractName}`)
12+
1313
// Note that the script needs the ABI which is generated from the compilation artifact.
1414
// Make sure contract is compiled and artifacts are generated
1515
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
16-
1716
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
18-
// 'web3Provider' is a remix global variable object
1917

20-
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
21-
22-
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer)
18+
// 'web3Provider' is a remix global variable object
19+
const provider = new ethers.BrowserProvider(web3Provider);
20+
const signer = await provider.getSigner(accountIndex);
2321

24-
const contract = await factory.deploy(...args)
22+
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
23+
const contract = await factory.deploy(...args);
2524

2625
// The contract is NOT deployed yet; we must wait until it is mined
27-
await contract.deployed()
28-
return contract
29-
}
26+
await contract.waitForDeployment();
27+
28+
return contract;
29+
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ethers } from "ethers"
12
import { deploy } from './deploy'
23

34
(async () => {
@@ -7,30 +8,30 @@ import { deploy } from './deploy'
78

89
// deploy ERC20
910
const erc20 = await deploy('MyToken', ['0x5B38Da6a701c568545dCfcB03FcB875f56beddC4'])
10-
console.log(`MyToken address: ${erc20.address}`)
11+
console.log(`MyToken address: ${await erc20.getAddress()}`)
1112

1213
// deploy Spender
13-
const spender = await deploy('Spender', [erc20.address])
14-
console.log(`Spender address: ${spender.address}`)
14+
const spender = await deploy('Spender', [await erc20.getAddress()])
15+
console.log(`Spender address: ${await spender.getAddress()}`);
1516

1617
// mint 1000000 token to 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
17-
await (await erc20.mint(accountWithToken, 1000000))
18+
await (await erc20.mint(accountWithToken, 1000000)).wait()
1819

1920
// check
2021
console.log('balance', (await erc20.balanceOf(accountWithToken)).toString())
2122

2223
// encode call 1 : Approve Spender to spend 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 balance (1000000)
23-
const data1 = erc20.interface.encodeFunctionData('approve', [spender.address, 1000000])
24+
const data1 = erc20.interface.encodeFunctionData('approve', [await spender.getAddress(), 1000000])
2425
// encode call 2 : Use Spender to send 100000 token to 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 from 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 balance
2526
const data2 = spender.interface.encodeFunctionData('send', [accountWithToken, accountNullBalance, 10000])
2627

2728
const executeBatch = [
28-
[erc20.address, 0, data1],
29-
[spender.address, 0, data2]
30-
]
29+
[await erc20.getAddress(), 0, data1],
30+
[await spender.getAddress(), 0, data2]
31+
];
3132

3233
console.log(executeBatch)
3334
} catch (e) {
3435
console.log(e.message)
3536
}
36-
})()
37+
})();

0 commit comments

Comments
 (0)