Skip to main content

Sending and Signing a Transaction

Nightly will prompt user to send transaction on their behalf, on a condition that application is connected to Nightly successfully. Application is required to follow the steps below for the transaction to be executed:

  1. Create new unsigned transaction.
  2. Nightly wallet sign and submit this transaction to Aptos.
  3. As an option, application can get back confirmation of status of this transaction by using a Aptos JSON RPC connection.

Signing single transaction

After a new transaction is created, application will prompt user's Nightly wallet to approve and send the transaction, by signing it. If the user approves transaction, Nightly will submit transaction details alongside with user's private key to the RPC.

In order to do so, please use signTransaction() method provided below. This will sing and return the transaction back to the application.

  async signTransaction(transaction: TransactionPayload) {
return await this._provider.signTransaction(transaction)
}
import { FaucetClient } from 'aptos'
import { NightlyWalletAdapter } from './nightly'
const faucetClient = new FaucetClient(TESTNET_URL, FAUCET_URL)
const NightlyAptos = new NightlyWalletAdapter()

const tx: TransactionPayload = {
type: 'entry_function_payload',
arguments: ['0x4834430bce35346ccadf1901ef0576d7d4247c4f31b08b8b7ae67884a323ab68', 1000],
function: '0x1::coin::transfer',
type_arguments: ['0x1::aptos_coin::AptosCoin']
}

const bcsTxn = await NightlyAptos.signTransaction(tx)
const result = await faucetClient.submitSignedBCSTransaction(bcsTxn)

Signing Multiple Transactions

If you would like to execute the above method on multiple transactions, we recommend do it in a single call with signAllTransactions() method. This will sign all transactions and return a Promise for an object containing the signature.

public async signAllTransactions(transactions: TransactionPayload[]): Promise<Uint8Array[]> {
return await this._provider.signAllTransactions(transactions)
}
import { FaucetClient } from 'aptos'
import { NightlyWalletAdapter } from './nightly'
const faucetClient = new FaucetClient(TESTNET_URL, FAUCET_URL)
const NightlyAptos = new NightlyWalletAdapter()

const tx: TransactionPayload = {
type: 'entry_function_payload',
arguments: ['0x4834430bce35346ccadf1901ef0576d7d4247c4f31b08b8b7ae67884a323ab68', 1000],
function: '0x1::coin::transfer',
type_arguments: ['0x1::aptos_coin::AptosCoin']
}
const tx2: TransactionPayload = {
type: 'entry_function_payload',
arguments: ['0x4834430bce35346ccadf1901ef0576d7d4247c4f31b08b8b7ae67884a323ab68', 1000],
function: '0x1::coin::transfer',
type_arguments: ['0x1::aptos_coin::AptosCoin']
}
const bcsTxn = await NightlyAptos.signAllTransactions([tx, tx2])
for (const tx of bcsTxn) {
const result = await faucetClient.submitTransaction(tx)
}