@mysten/sui v2.0 and a new dApp Kit are here! Check out the migration guide
Mysten Labs SDKs
Transaction building

Sponsored Transactions

The transaction builder can support sponsored transactions by using the onlyTransactionKind flag when building the transaction.

const tx = new Transaction();

// ... add some transactions...

const kindBytes = await tx.build({ provider, onlyTransactionKind: true });

// construct a sponsored transaction from the kind bytes
const sponsoredtx = Transaction.fromKind(kindBytes);

// you can now set the sponsored transaction data that is required
sponsoredtx.setSender(sender);
sponsoredtx.setGasOwner(sponsor);
sponsoredtx.setGasPayment(sponsorCoins);