Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ts-sdk] Update Instructions for using CLI to get compiled modules #4537

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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