Skip to content

Instantly share code, notes, and snippets.

@magnum6actual
Created July 24, 2025 16:38
Show Gist options
  • Select an option

  • Save magnum6actual/4eda9fa36e73377de93fc1ea6b884b19 to your computer and use it in GitHub Desktop.

Select an option

Save magnum6actual/4eda9fa36e73377de93fc1ea6b884b19 to your computer and use it in GitHub Desktop.
private async buildSignAndSubmitBCS(account: Account, func: string, args: any[]): Promise<UserTransactionResponse> {
const parts = func.split("::");
const moduleAddress = parts[0];
const moduleName = parts[1];
const functionName = parts[2];
const chainId = await this.getChainId(); // locally cached chainId
const sequenceNumber = BigInt(0); // 0 for orderless transactions
const entryFunction = new EntryFunction(
new ModuleId(AccountAddress.from(moduleAddress), new Identifier(moduleName)),
new Identifier(functionName),
[], // type arguments
args
);
// Create the proper orderless transaction payload
let transactionPayload;
if (this.useOrderlessTransactions) {
const nonce = this.generateNonce();
// Use the proper orderless transaction structure
transactionPayload = new TransactionInnerPayloadV1(
new TransactionExecutableEntryFunction(entryFunction),
new TransactionExtraConfigV1(
undefined, // multisigAddress
nonce.value // replayProtectionNonce as bigint
)
);
} else {
// Use regular payload for non-orderless transactions
transactionPayload = new TransactionPayloadEntryFunction(entryFunction);
}
const rawTransaction = new RawTransaction(
account.accountAddress,
sequenceNumber,
transactionPayload,
BigInt(2000), // maxGasAmount
BigInt(100), // gasUnitPrice
BigInt(Math.floor(Date.now() / 1000) + 30), // expireTimestamp (30 seconds from now)
new ChainId(chainId)
);
const txn = new SimpleTransaction(rawTransaction);
const authenticator = account.signTransactionWithAuthenticator(txn);
const response = await this.client.transaction.submit.simple({
transaction: txn,
senderAuthenticator: authenticator,
});
const executionResult = (await this.client.waitForTransaction({
transactionHash: response.hash,
})) as UserTransactionResponse;
return executionResult;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment