Ada - Marlowe TypeScript SDK

Apr 3, 2024
   41

Prerequisites:

  1. Ada Recommended Wallet https://www.namiwallet.io/
  2. Node.js: https://nodejs.org/en/download
  3. React.js: https://react.dev/learn/installation
  4. NPX: https://www.npmjs.com/package/npx



Package Installs:

npm install @marlowe.io/wallet
npm install @marlowe.io/runtime-lifecycle


Source Code:


App.js


import * as wallet from "@marlowe.io/wallet";
import { mkRuntimeLifecycle } from "@marlowe.io/runtime-lifecycle/browser";


//Get installed Browser Wallets
const installedBrowserWallets = wallet.getInstalledWalletExtensions();


//Get Current Wallet Name
const walletName = installedBrowserWallets[0].name;
const runtimeURL = "https://marlowe-preprod-patch6-rt-webserver-peaceful-zeppelin-242e56.us1.demeter.run";




//Connect to the Runtime
const runtimeLifecycle = await mkRuntimeLifecycle({
  walletName: walletName,
  runtimeURL: runtimeURL,
});


//Get User Wallet
const userWallet = await wallet.mkBrowserWallet(walletName);
const amount = await userWallet.getLovelaces();


//Close Contract


try {
  await runtimeLifecycle.contracts.createContract({
    contract: 'close'
  });
} catch (error) {
  console.log(error)
}
console.log("Success")




function App() {
  return (
   
     
       

Connected Wallet: {walletName}

     
      Available ADA: {amount.toString()}
     
   
  );
}


export default App;

 

Simple Cardano Contract:


pragma solidity ^0.8.0;

contract SimpleSmartContract {
uint256 public value;

function setValue(uint256 newValue) public {
value = newValue;
}

function getValue() public view returns (uint256) {
return value;
}
}