Await an application-owned onSigned callback to durably save the signed result
and its original account/network before broadcasting. If saving fails, submission
is never requested.
expectedNetworkHash comes from trusted application configuration, and client
must already be connected to and verified against that network.
import type { CoreThruputClient } from "@thruputchain/client";
import {
parseWalletSession,
parseWalletNetworkHash,
type SignTransactionResult,
type WalletAccount,
type WalletProvider,
} from "@thruputchain/client/provider";
import {
createProviderWalletClient,
type PrepareExecutionRequest,
} from "@thruputchain/client/wallet";
async function sendWithWallet(
client: CoreThruputClient,
provider: WalletProvider,
expectedNetworkHash: string,
request: PrepareExecutionRequest,
onSigned: (pending: SignTransactionResult & {
account: WalletAccount;
networkHash: string;
}) => Promise<void>,
) {
const networkHash = parseWalletNetworkHash(expectedNetworkHash);
const session = parseWalletSession(await provider.request({ method: "connect" }));
if (session.networkHash !== networkHash) {
throw new Error("Wallet network does not match the application network");
}
const account = session.accounts[0];
if (!account) throw new Error("No authorized account");
const wallet = createProviderWalletClient({
client, provider, account, networkHash,
});
try {
const transaction = await wallet.prepareExecution(request);
const signed = await wallet.signTransaction(transaction);
await onSigned({ ...signed, account, networkHash });
// On submit failure, recover using the saved hash and original network.
return await wallet.submitTransaction(signed);
} finally {
wallet.dispose();
}
}
Synchronously bind a pubkey provider account without modifying the RPC client. Does not connect or request permission: first await provider
connectand validate its session. Snapshots account/network configuration, validates account derivation and any validated client network identity, and subscribes to changes. Supply the application's trusted expected network hash, not a value adopted from the wallet. The RPC client must be connected to and verified against that same network. Every native client carries a discovered network identity, checked here. See ProviderWalletClient for invalidation and concurrency rules. Providers own signing UI deadlines. Execution controls bound submission and observation after signing; they cannot cancel a broadcast already sent.