Skip to content

Commit

Permalink
[ts-sdk] Update Instructions for using CLI to get compiled modules (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
666lcz authored Sep 13, 2022
1 parent 6edfdb9 commit 7485592
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
20 changes: 11 additions & 9 deletions sdk/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,26 @@ To publish a package:

```typescript
import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js';
import * as fs from 'fs/promises';
const { execSync } = require('child_process');
// Generate a new Keypair
const keypair = new Ed25519Keypair();
const signer = new RawSigner(
keypair,
new JsonRpcProvider('https://gateway.devnet.sui.io:443')
);
const bytecode = await fs.readFile('path/to/project/build/project_name/bytecode_modules/module_name.mv', 'base64');
const publishTxn = await signer.publish(
{
compiledModules: [bytecode.toString()],
gasBudget: 1000
}
const compiledModules = JSON.parse(
execSync(
`${cliPath} move build --dump-bytecode-as-base64 --path ${packagePath}`,
{ encoding: 'utf-8' }
)
);
const publishTxn = await signer.publish({
compiledModules,
gasBudget: 10000,
});
console.log('publishTxn', publishTxn);
```


Alternatively, a Secp256k1 can be initiated:

```typescript
Expand All @@ -215,4 +217,4 @@ const signer = new RawSigner(
keypair,
new JsonRpcProvider('https://gateway.devnet.sui.io:443')
);
```
```
4 changes: 4 additions & 0 deletions sdk/typescript/src/signers/signer-with-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ export abstract class SignerWithProvider implements Signer {
return await this.signAndExecuteTransaction(txBytes);
}

/**
* Publish a Move package on chain
* @param transaction See {@link PublishTransaction}
*/
async publish(
transaction: PublishTransaction
): Promise<SuiTransactionResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,28 @@ export interface MoveCallTransaction {
gasBudget: number;
}

/**
* Transaction type used for publishing Move modules to the Sui.
*
* Use the util methods defined in [utils/publish.ts](../../utils/publish.ts)
* to get `compiledModules` bytes by leveraging the sui
* command line tool.
*
* ```
* const { execSync } = require('child_process');
* const modulesInBase64 = JSON.parse(execSync(
* `${cliPath} move build --dump-bytecode-as-base64 --path ${packagePath}`,
* { encoding: 'utf-8' }
* ));
*
* // Include the following line if you are using `LocalTxnDataSerializer`, skip
* // if you are using `RpcTxnDataSerializer`
* // const modulesInBytes = modules.map((m) => Array.from(new Base64DataBuffer(m).getData()));
* // ... publish logic ...
* ```
*
*/
export interface PublishTransaction {
/**
* Transaction type used for publishing Move modules to the Sui.
* Should be already compiled using `sui-move`, example:
* ```
* $ sui move build
* $ cat build/project_name/bytecode_modules/module.mv
* ```
* In JS:
*
* ```
* // If you are using `RpcTxnDataSerializer`,
* let file = fs.readFileSync('./move/build/project_name/bytecode_modules/module.mv', 'base64');
* let compiledModules = [file.toString()]
*
* // If you are using `LocalTxnDataSerializer`,
* let file = fs.readFileSync('./move/build/project_name/bytecode_modules/module.mv');
* let modules = [ Array.from(file) ];
*
* // ... publish logic ...
* ```
*
* Each module should be represented as a sequence of bytes.
*/
compiledModules: ArrayLike<string> | ArrayLike<ArrayLike<number>>;
gasPayment?: ObjectId;
gasBudget: number;
Expand Down

0 comments on commit 7485592

Please sign in to comment.