diff --git a/src/tx-builder.ts b/src/tx-builder.ts index 7f46d609..1fbf0097 100644 --- a/src/tx-builder.ts +++ b/src/tx-builder.ts @@ -11,7 +11,7 @@ import { } from '@mysten/sui.js/client'; import { Keypair } from '@mysten/sui.js/dist/cjs/cryptography'; import { TransactionBlock, TransactionObjectInput, TransactionResult } from '@mysten/sui.js/transactions'; -import { utils as ethersUtils } from 'ethers'; +import { Bytes, utils as ethersUtils } from 'ethers'; import tmp from 'tmp'; import { updateMoveToml } from './utils'; @@ -243,20 +243,29 @@ export class TxBuilder { }); } - async publishPackage(packageName: string, moveDir: string = `${__dirname}/../move`): Promise { + async getContractBuild( + packageName: string, + moveDir: string = `${__dirname}/../move`, + ): Promise<{ modules: string[]; dependencies: string[]; digest: Bytes }> { updateMoveToml(packageName, '0x0', moveDir); tmp.setGracefulCleanup(); const tmpobj = tmp.dirSync({ unsafeCleanup: true }); - const { modules, dependencies } = JSON.parse( + const { modules, dependencies, digest } = JSON.parse( execSync(`sui move build --dump-bytecode-as-base64 --path ${path.join(moveDir, packageName)} --install-dir ${tmpobj.name}`, { encoding: 'utf-8', stdio: 'pipe', // silent the output }), ); + return { modules, dependencies, digest }; + } + + async publishPackage(packageName: string, moveDir: string = `${__dirname}/../move`): Promise { + const { modules, dependencies } = await this.getContractBuild(packageName, moveDir); + return this.tx.publish({ modules, dependencies,