Deno & Fetch

Using Deno (or Node) & fetch to build, sign* and submit a transaction

Introduction

There are two ways to create a transaction, the first one is by passing the Cardano wallet address for the utxos (only available on testnet networks), and the second one (required for production) usually used with a frontend (wallet extension), requires to get a list of all cbor utxos to be used for the transaction.

Objectives

This example sends 10ADA from one wallet to another.

The wallets are on Preprod network and using a CIP-30 compatible wallet (So the signature is done in the browser)

Requirements

  • A Cardano wallet with ADA

  • A wallet to send ADA to

  • A wallet extension to sign the transaction

  • An API key

API Request Structure

Payload Format (Using an address as utxos)

Important: This demo is meant for educational and testing purposes only. In production, please pass the UTXO list for your wallet. We recommend using the @ada-anvil/weldarrow-up-right wallet connector to easily retrieve UTXOs from connected wallets. In this example, the API will fetch the UTXO list for you and automatically determine the UTXO(s) to be used for the transaction.

Implementation

Configuration and Parameters (using Deno and Fetch)

Using a preprod wallet all value needed for a transaction

Request Body

Body Structure for creating a basic transaction using the previously collected values.

API Call (using Deno and Fetch)

Basic POST call with Fetch

Deno Command

Output

The Whole File (Deno Version)

chevron-rightbasic-transaction.tshashtag

Using Fetched Utxos

Payload (Using a list of utxos)

You can use this payload when you can fetch the utxos, for example, when you have a wallet extension

Add the required UTXOs for your transaction. (usually all of them)

Get UTXO

You can retrieve your UTXOs from your wallet using these functions in the browser console. (Example: Chrome console with Eternl)

Then, copy your UTXO array and include it as a parameter in the request body, as shown below.

Params

API POST Request Body

Body Structure for creating a basic transaction using the previously collected values.

Fetch Command with Deno

Basic POST call with Fetch

Deno Command

Output


Sign and Submit the Transaction

The transaction can be sign and submitted.

https://github.com/Cardano-Forge/anvil-api/blob/main/docs/guides/transaction/signing-transaction.mdchevron-rightSubmit Transactionchevron-right

The Whole File (Deno Version)

chevron-rightbasic-transaction.tshashtag

Last updated

Was this helpful?