我正在尝试使用 @mysten/sui typescript SDK 构建和发布现有的 SUI 包(智能合约)。执行交易模拟时失败,模拟结果中出现
PublishErrorNonZeroAddress in command 0
错误消息。
在Move.toml中,版本设置为2024.beta,对于sui dependentenci,我尝试了framework/testnet和framework/devnet。 @mysten/sui sdk版本是1.12.0
我尝试在开发网和测试网网络上这样做,但没有成功。另一方面,我能够使用 CLI 构建和部署包,没有任何问题。
这是我的代码示例:
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);
tx.publish({ modules, dependencies });
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);
}
对我有用的解决方案是使用 sui CLI 将 env 设置到主网。像这样: sui client switch --env mainnet