diff --git a/packages/sdk/src/Actions/ContractAction.test.ts b/packages/sdk/src/Actions/ContractAction.test.ts index b8dc4cea8..381404f66 100644 --- a/packages/sdk/src/Actions/ContractAction.test.ts +++ b/packages/sdk/src/Actions/ContractAction.test.ts @@ -1,6 +1,6 @@ import type { Config } from '@wagmi/core'; -import { zeroAddress } from 'viem'; -import { beforeEach, describe, test } from 'vitest'; +import { isAddress, zeroAddress } from 'viem'; +import { beforeEach, describe, expect, test } from 'vitest'; import { setupConfig, testAccount } from '../../test/viem'; import { ContractAction } from './ContractAction'; @@ -22,6 +22,21 @@ describe('ContractAction', () => { }, ); const address = await action.deploy(); - console.log(address); + expect(isAddress(address)).toBe(true); + }); + + test('can successfully be initialized after deployment', async () => { + const action = new ContractAction( + { config, account: testAccount }, + { + chainId: BigInt(31_337), + target: zeroAddress, + selector: '0xdeadbeef', + value: 2n, + }, + ); + await action.deploy(); + await action.initialize(); + console.log(await action.chainId()); }); }); diff --git a/packages/sdk/src/Deployable/DeployableTarget.ts b/packages/sdk/src/Deployable/DeployableTarget.ts index de82da3b4..6f1cbf293 100644 --- a/packages/sdk/src/Deployable/DeployableTarget.ts +++ b/packages/sdk/src/Deployable/DeployableTarget.ts @@ -1,7 +1,10 @@ -import { deployContract } from '@wagmi/core'; +import { + deployContract, + waitForTransactionReceipt, + writeContract, +} from '@wagmi/core'; import type { Address, Hash, WaitForTransactionReceiptParameters } from 'viem'; import { DeployableAlreadyDeployedError } from '../errors'; -import { getDeployedContractAddress } from '../utils'; import { Deployable, type DeployableOptions, @@ -19,19 +22,36 @@ export class DeployableTarget extends Deployable { this.isBase = isBase; } - public override async deploy( + public async initialize( _payload?: Payload, _options?: DeployableOptions, waitParams: Omit = {}, - ): Promise
{ + ) { + const payload = _payload || this._payload; const config = _options?.config || this._config; - const address = await getDeployedContractAddress( - config, - this.deployRaw(_payload, _options), - waitParams, - ); - this._address = address; - return address; + console.log(payload); + const { abi, args } = this.buildParameters(payload); + console.log(args); + const hash = await writeContract(config, { + ...this.optionallyAttachAccount(_options?.account), + abi, + args, + functionName: 'initialize', + address: this.assertValidAddress(), + }); + await waitForTransactionReceipt(config, { + ...waitParams, + hash, + }); + } + + public override async deploy( + payload?: Payload, + options?: DeployableOptions, + waitParams?: Omit, + ): Promise
{ + await super.deploy(payload, options, waitParams); + return this.assertValidAddress(); } public override async deployRaw( @@ -41,9 +61,11 @@ export class DeployableTarget extends Deployable { if (this.address) throw new DeployableAlreadyDeployedError(this.address); const payload = _payload || this._payload; const config = _options?.config || this._config; + const { args, ...deployment } = this.buildParameters(payload); return await deployContract(config, { - ...this.buildParameters(payload), + ...deployment, ...this.optionallyAttachAccount(_options?.account), + args: [], }); } }