>

>

2. The Envelope: Building and Signing

Building and Signing ✍️

The Envelope: Building and Signing

Almost there! We have our clauses and our gas estimate. Now we need to put them into a formal Transaction Body.

Think of the Transaction Body as the official paperwork. It includes your clauses, the gas limit, and other metadata like expiration.

const txBody = await thor.transactions.buildTransactionBody(
  clauses,
  gasResult.totalGas
);
const txBody = await thor.transactions.buildTransactionBody(
  clauses,
  gasResult.totalGas
);
const txBody = await thor.transactions.buildTransactionBody(
  clauses,
  gasResult.totalGas
);

Now comes the most important part: Signing. Without a digital signature, the network won't know the transaction is really from you!

In the SDK, this involves three friends working together: your Internal Wallet, a Provider, and a Signer.

The Signer takes your transaction body and your private key to create a unique cryptographic proof. 'In JavaScript, this means...'

const signer = await provider.getSigner(address);
const rawSignedTx = await signer.signTransaction(txBody, privateKey);
const signer = await provider.getSigner(address);
const rawSignedTx = await signer.signTransaction(txBody, privateKey);
const signer = await provider.getSigner(address);
const rawSignedTx = await signer.signTransaction(txBody, privateKey);

Nice! Your transaction is now signed and sealed. It's ready for the world!