I'm trying to build and publish new SUI package (smart contract) using @mysten/sui typescript SDK. When executing transaction simulation it fails with PublishErrorNonZeroAddress in command 0
error message in the simulation result.
In the Move.toml, edition is set to 2024.beta and for sui dependenci i have tried both framework/testnet and framework/devnet. @mysten/sui sdk version is 1.12.0
I have tried to do so on devnet and testnet networks without success. On the other hand, i was able to build and deploy package using CLI without any issues.
Here is my code example:
import path from 'path';
import { execSync } from 'child_process';
import { getFullnodeUrl, SuiClient, } from '@mysten/sui/client';
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { Transaction } from '@mysten/sui/transactions';
const client = new SuiClient({ url: getFullnodeUrl('testnet') });
const signer = Ed25519Keypair.deriveKeypair("my seed phrase");
const contractURI = path.resolve(__dirname, "../", "./contract");
const { modules, dependencies } = JSON.parse(
execSync(`sui move build --dump-bytecode-as-base64 --path ${contractURI}`, {
encoding: 'utf-8',
})
);
const tx = new Transaction();
tx.setSender(signer.getPublicKey().toSuiAddress());
tx.setGasBudget(1000000000);
const upgradeCap = tx.publish({ modules, dependencies });
tx.transferObjects([upgradeCap], signer.getPublicKey().toSuiAddress());
const txBytes = await tx.build({ client });
const signature = (await signer.signTransaction(txBytes)).signature;
const simulationResult = await client.dryRunTransactionBlock({ transactionBlock: txBytes });
if (simulationResult.effects.status.status === "success") {
const result = await client.executeTransactionBlock({
transactionBlock: txBytes,
signature,
options: {
showEffects: true,
}
});
console.log("Result: ", result);
}
else {
console.log("Simulation failed: ", simulationResult);
}
Solution that worked for me was to set env to the mainnet using sui CLI. Like so: sui client switch --env mainnet