Skip to content

Commit 662aa31

Browse files
authored
deploys global contract to hardcoded address (#5164)
updates the deploy-contract command example to deploy the global contract to a hardcoded address proves that we can deploy the contract to a predetermined address of our choosing
1 parent 5fc50ab commit 662aa31

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

ironfish-cli/src/commands/evm/deploy-contract.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44
import { LegacyTransaction } from '@ethereumjs/tx'
5-
import { Account, Address } from '@ethereumjs/util'
5+
import { Account, Address, hexToBytes } from '@ethereumjs/util'
66
import { generateKey } from '@ironfish/rust-nodejs'
77
import { Assert, ContractArtifact, IronfishEvm } from '@ironfish/sdk'
88
import { ethers } from 'ethers'
@@ -32,19 +32,16 @@ export class TestEvmCommand extends IronfishCommand {
3232
await node.chain.blockchainDb.stateManager.putAccount(senderAddress, senderAccount)
3333
await node.chain.blockchainDb.stateManager.commit()
3434

35-
// Deploy the global contract
36-
const tx = new LegacyTransaction({
37-
gasLimit: 1_000_000n,
38-
data: ContractArtifact.bytecode,
39-
})
40-
41-
const result = await evm.runTx({ tx: tx.sign(senderPrivateKey) })
42-
43-
const globalContractAddress = result.createdAddress
35+
const globalContractAddress = Address.fromString(
36+
'0xffffffffffffffffffffffffffffffffffffffff',
37+
)
4438

45-
if (!globalContractAddress) {
46-
this.error('Contract creation of address failed')
47-
}
39+
await node.chain.blockchainDb.stateManager.checkpoint()
40+
await node.chain.blockchainDb.stateManager.putContractCode(
41+
globalContractAddress,
42+
hexToBytes(ContractArtifact.deployedBytecode),
43+
)
44+
await node.chain.blockchainDb.stateManager.commit()
4845

4946
const contract = await node.chain.blockchainDb.stateManager.getAccount(
5047
globalContractAddress,
@@ -58,24 +55,24 @@ export class TestEvmCommand extends IronfishCommand {
5855

5956
const globalContract = new ethers.Interface(ContractArtifact.abi)
6057

61-
const data2 = globalContract.encodeFunctionData('shield', [
58+
const data = globalContract.encodeFunctionData('shield', [
6259
Buffer.from(senderKey.publicAddress, 'hex'),
6360
2n,
6461
100n,
6562
])
6663

67-
const tx2 = new LegacyTransaction({
68-
nonce: 1n,
64+
const tx = new LegacyTransaction({
65+
nonce: 0n,
6966
gasLimit: 100_000n,
7067
to: globalContractAddress,
71-
data: data2,
68+
data: data,
7269
})
7370

74-
const result2 = await evm.runTx({ tx: tx2.sign(senderPrivateKey) })
71+
const result = await evm.runTx({ tx: tx.sign(senderPrivateKey) })
7572

76-
Assert.isEqual(result2.receipt.logs.length, 1)
73+
Assert.isEqual(result.receipt.logs.length, 1)
7774

78-
const log = result2.receipt.logs[0]
75+
const log = result.receipt.logs[0]
7976

8077
this.log('Contract Address')
8178
this.log(Buffer.from(log[0]).toString('hex'))

0 commit comments

Comments
 (0)