-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
How to execute a publish transaction using TS SDK #20703
Comments
import 'dotenv/config';
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { fromBase64 } from '@mysten/sui/utils';
import { SuiClient } from '@mysten/sui/client';
import path, { dirname } from 'path';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { Transaction } from '@mysten/sui/transactions';
const priv_key = process.env.PRIVATE_KEY;
if (!priv_key) {
console.log('Error: Priv Key not set in env');
process.exit(1);
}
const keypair = Ed25519Keypair.fromSecretKey(fromBase64(priv_key).slice(1));
const node_url = process.env.NODE_URL;
if (!node_url) {
console.log('Error: Node url not found in env');
process.exit(1);
}
const client = new SuiClient({ url: node_url });
const path_to_contract = path.join(dirname(fileURLToPath(import.meta.url)), './contracts/sources');
console.log('Building contract');
const { dependencies, modules } = JSON.parse(
execSync(`sui move build --dump-bytecode-as-base64 --path ${path_to_contract}`, {
encoding: 'utf-8',
}),
);
console.log('Deploying contract');
console.log(`Deploying from: ${keypair.toSuiAddress()}`);
const deploy_trx = new Transaction();
deploy_trx.setSender(keypair.getPublicKey().toSuiAddress());
const [upgrade_cap] = deploy_trx.publish({
modules,
dependencies,
});
deploy_trx.transferObjects([upgrade_cap], keypair.getPublicKey().toSuiAddress());
const { objectChanges, balanceChanges } = await client.signAndExecuteTransaction({
signer: keypair,
transaction: deploy_trx,
options: {
showBalanceChanges: true,
showEffects: true,
showEvents: true,
showInput: true,
showObjectChanges: true,
showRawInput: false,
},
});
// If you want to sign and execute separately:
const { bytes, signature } = await keypair.signTransaction(await deploy_trx.build({ client }));
const { objectChanges, balanceChanges } = await client.executeTransactionBlock({
transactionBlock: bytes,
signature,
options: {
showBalanceChanges: true,
showEffects: true,
showEvents: true,
showInput: true,
showObjectChanges: true,
showRawInput: false,
},
});
console.log(objectChanges, balanceChanges); |
the migration guide here might also be helpful: https://sdk.mystenlabs.com/typescript/migrations/sui-1.0 |
@jdbertron hope that the updated example from @hayes-mysten and the migration guide will help you here. Feel free to let us know otherwise. |
Thanks. I'll apply the migratiin stuff tomorrow.
…
On Dec 19, 2024 at 8:33 PM, stefan-mysten ***@***.***> wrote:
@jdbertron hope that the updated example from @hayes-mysten and the migration guide will help you here. Feel free to let us know otherwise.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
stefan-mysten
changed the title
Sui doc content issue or request
How to execute a publish transaction using TS SDK
Dec 20, 2024
That worked. Thanks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ever since RawSigner got deprecated and TransactionBlock got renamed, I can't figure out how to deploy a contract. I have new code that seems to execute, but fails with Error: No sui client passed to Transaction#build, but transaction data was not sufficient to build offline.
Please provide a working example.
The text was updated successfully, but these errors were encountered: