Skip to content

Commit

Permalink
Declare return tx hash (#332)
Browse files Browse the repository at this point in the history
* [skip testnet]

---------

Co-authored-by: Daniel Voronov <[email protected]>
Co-authored-by: Daniel Voronov <[email protected]>
  • Loading branch information
3 people authored Mar 14, 2023
1 parent f54ccef commit 1ebae50
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export abstract class Account {
* Declare the contract class corresponding to the `contractFactory`
* @param contractFactory
* @param options
* @returns the hash of the declared class
* @returns transaction hash
*/
public async declare(
contractFactory: StarknetContractFactory,
Expand Down
5 changes: 2 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export class StarknetContractFactory {
/**
* Declare a contract class.
* @param options optional arguments to class declaration
* @returns the class hash as a hex string
* @returns transaction hash as a hex string
*/
async declare(options: DeclareOptions = {}): Promise<string> {
const executed = await this.hre.starknetWrapper.declare({
Expand All @@ -382,14 +382,13 @@ export class StarknetContractFactory {
}

const executedOutput = executed.stdout.toString();
const classHash = extractClassHash(executedOutput);
const txHash = extractTxHash(executedOutput);

return new Promise((resolve, reject) => {
iterativelyCheckStatus(
txHash,
this.hre.starknetWrapper,
() => resolve(classHash),
() => resolve(txHash),
(error) => {
reject(new StarknetPluginError(`Declare transaction ${txHash}: ${error}`));
}
Expand Down
11 changes: 5 additions & 6 deletions www/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,8 @@ describe("My Test", function () {
// not compatible with accounts deployed with Starknet CLI
const account = await starknet.OpenZeppelinAccount.getAccountFromAddress(...);
const contractFactory = await starknet.getContractFactory("MyContract");
const classHash = await account.declare(contractFactory); // class declaration

// two ways to obtain the class hash
expect(classHash).to.equal(await contractFactory.getClassHash());
const txHash = await account.declare(contractFactory); // class declaration
const classHash = await contractFactory.getClassHash();

const constructorArgs = { initial_balance: 0 };
const options = { maxFee: ... };
Expand Down Expand Up @@ -307,8 +305,9 @@ it("should estimate fee", async function () {
it("should forward to the implementation contract", async function () {
const implementationFactory = await starknet.getContractFactory("contract");
const account = ...;
const implementationClassHash = await account.declare(implementationFactory);

const txHash = await account.declare(implementationFactory);
const implementationClassHash = await implementationFactory.getClassHash();

const proxyFactory = await starknet.getContractFactory("delegate_proxy");
await account.declare(proxyFactory);
const proxy = await account.deploy(proxyFactory, {
Expand Down

0 comments on commit 1ebae50

Please sign in to comment.