Skip to content

A UTxO RPC Provider for Mesh Js Transaction Builder Library

Notifications You must be signed in to change notification settings

utxorpc/mesh-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💡 Basic Usage

Below is an example of how to use the UTxO RPC provider with Mesh to build and submit a transaction.

// Step #1
// Import Mesh SDK and UTxO RPC provider
import { Transaction, MeshWallet } from "@meshsdk/core";
import { U5CProvider } from './u5c';


async function main() {

    // Step #2
    // Create a new U5C provider
    const provider = new U5CProvider({
        url: "http://localhost:50051",
        headers: {
            "dmtr-api-key": "<api-key>",
        },
    });

    // Step #3
    // Create a new wallet from a mnemonic
    const wallet = new MeshWallet({
    networkId: 0, // 0: testnet, 1: mainnet
    fetcher: provider,
    submitter: provider,
    key: {
        type: 'mnemonic',
        words: ["solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
    },
    });

    // Optional: Print the wallet address
    console.log(wallet.getChangeAddress())

    // Optional: Print the wallet utxos
    console.log(await provider.fetchAddressUTxOs(wallet.getChangeAddress()))

    // Step #4
    // Create an example transaction that sends 5 ADA to an address
    const tx = new Transaction({ initiator: wallet, verbose: false })
    .sendLovelace(
        'addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr',
        '5000000'
    );
    const unsignedTx = await tx.build();

    // Step #5
    // Sign the transaction
    const signedTx = wallet.signTx(unsignedTx);

    // Step #6
    // Submit the transaction to the blockchain network
    const txId = await provider.submitTx(signedTx);

    // Optional: Print the transaction ID
    console.log("Transaction ID", txId);
}

main().catch(console.error);

About

A UTxO RPC Provider for Mesh Js Transaction Builder Library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published