Skip to content

Commit

Permalink
Merge pull request #290 from MeshJS/docs-update
Browse files Browse the repository at this point in the history
v1.7.2
  • Loading branch information
jinglescode authored Sep 4, 2024
2 parents f07ff08 + a80ea51 commit 3d989e6
Show file tree
Hide file tree
Showing 25 changed files with 212 additions and 75 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
<div align="center">

![Mesh Logo](https://meshjs.dev/logo-mesh/mesh.png)
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://meshjs.dev/logo-mesh/white/logo-mesh-white-512x512.png" width="200">
<source media="(prefers-color-scheme: light)" srcset="https://meshjs.dev/logo-mesh/black/logo-mesh-black-512x512.png" width="200">
<img alt="mesh logo" src="https://meshjs.dev/logo-mesh/mesh.png">
</picture>

<hr />
<h2 align="center" style="border-bottom: none">Mesh SDK</h2>
<h1 style="border-bottom: none"><a href='https://meshjs.dev/'>Mesh</a> TypeScript SDK</h1>

[![Licence](https://img.shields.io/github/license/meshjs/mesh)](https://github.com/meshjs/mesh/blob/master/LICENSE)
[![Build](https://github.com/meshjs/mesh/actions/workflows/build.yml/badge.svg)](https://github.com/meshjs/mesh/actions/workflows/build.yml)
[![Package](https://github.com/meshjs/mesh/actions/workflows/publish.yml/badge.svg)](https://github.com/meshjs/mesh/actions/workflows/publish.yml)
[![Licence](https://img.shields.io/github/license/meshjs/mesh)](https://github.com/meshjs/mesh/blob/master/LICENSE)
[![Build](https://github.com/meshjs/mesh/actions/workflows/build.yml/badge.svg)](https://github.com/meshjs/mesh/actions/workflows/build.yml)
[![Package](https://github.com/meshjs/mesh/actions/workflows/publish.yml/badge.svg)](https://github.com/meshjs/mesh/actions/workflows/publish.yml)

[![Twitter/X](https://img.shields.io/badge/Follow%20us-@MeshJS-blue?logo=x&style=for-the-badge)](https://x.com/meshsdk)
[![NPM](https://img.shields.io/npm/v/%40meshsdk%2Fcore?style=for-the-badge)](https://www.npmjs.com/package/@meshsdk/core)
[![Twitter/X](https://img.shields.io/badge/Follow%20us-@MeshJS-blue?logo=x&style=for-the-badge)](https://x.com/meshsdk)
[![NPM](https://img.shields.io/npm/v/%40meshsdk%2Fcore?style=for-the-badge)](https://www.npmjs.com/package/@meshsdk/core)

<strong>All-in-one web3 SDK for Cardano apps</strong>

<hr/>
</div>

<hr />

Mesh is an open-source library designed to make building dApps accessible. Whether you're a beginner developer, startup, web3 market leader, or a large enterprise, Mesh makes web3 development easy with reliable, scalable, and well-engineered APIs & developer tools.

Explore the features on [Mesh Playground](https://meshjs.dev/).

## What's inside?

This Turborepo includes the following packages/apps:
This repo includes the following packages/apps:

### Packages

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Link from "~/components/link";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";
import Codeblock from "~/components/text/codeblock";

export default function TransactionGetTxbuilder() {
return (
<TwoColumnsScroll
sidebarTo="getTxbuilder"
title="Get Txbuilder"
leftSection={Left()}
/>
);
}

function Left() {
let code1 = ``;
code1 += `const tx = new Transaction({ initiator: wallet });\n`;
code1 += `tx.foo();\n`;
code1 += `\n`;
code1 += `tx.txBuilder.bar()\n`;

let code2 = `tx.txBuilder.meshTxBuilderBody;`;

return (
<>
<p>
The <Link href="/apis/txbuilder">TxBuilder</Link> is a powerful
low-level APIs that allows you to build and sign transactions. You can
get a new instance of TxBuilder by calling <code>txBuilder</code>. Doing
so allows you to access the low-level APIs of TxBuilder,{" "}
<Link href="https://docs.meshjs.dev/transactions/classes/MeshTxBuilder">
check the docs
</Link>{" "}
for all the available methods.
</p>
<Codeblock data={code1} />
<p>
For example, you can get the <code>meshTxBuilderBody</code> to retrieve
the transaction JSON. This is useful for debugging and understanding how
the transaction is built.
</p>
<Codeblock data={code2} />
</>
);
}
14 changes: 10 additions & 4 deletions apps/playground/src/pages/apis/transaction/basics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Intro } from "../common";
import TransactionBegin from "./begin";
import TransactionCip20 from "./cip20";
import TransactionCoinSelection from "./coin-selection";
import TransactionGetTxbuilder from "./get-txbuilder";
import TransactionHandle from "./handle";
import TransactionMultisig from "./multisig";
import TransactionSendAssets from "./send-assets";
Expand All @@ -26,11 +27,13 @@ const ReactPage: NextPage = () => {
{ label: "Send value", to: "sendValue" },
{ label: "Multi-signature", to: "multisig" },

{ label: "Send assets to Handle", to: "handler" },
{ label: "Send assets to Begin ID", to: "begin" },

{ label: "Coin selection", to: "coinSelection" },

{ label: "Get txbuilder", to: "getTxbuilder" },

{ label: "ADA Handle", to: "handler" },
{ label: "Begin ID", to: "begin" },

{ label: "Set metadata", to: "metadata" },
{ label: "Set transaction message", to: "cip20" },

Expand Down Expand Up @@ -69,10 +72,13 @@ const ReactPage: NextPage = () => {
<TransactionSendValue />
<TransactionMultisig />

<TransactionCoinSelection />

<TransactionGetTxbuilder />

<TransactionHandle />
<TransactionBegin />

<TransactionCoinSelection />
<TransactionSetMetadata />
<TransactionCip20 />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ function Right() {
recipient: address,
};

// create transaction
const tx = new Transaction({ initiator: wallet }).setNetwork("preprod");
const tx = new Transaction({ initiator: wallet });
tx.setNetwork("preprod");
tx.mintAsset(forgingScript, asset);

const unsignedTx = await tx.build();
Expand Down
3 changes: 3 additions & 0 deletions apps/playground/src/pages/apis/utilities/resolvers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ResolvePaymentKeyHash from "./resolve-payment-key-hash";
import ResolvePlutusScriptAddress from "./resolve-plutus-script-address";
import ResolvePlutusScriptHash from "./resolve-plutus-script-hash";
import ResolvePrivateKey from "./resolve-private-key";
import ResolveScriptHash from "./resolve-script-hash";
import ResolveSlotNumber from "./resolve-slot-number";
import ResolveRewardAddress from "./resolve-stake-address";
import ResolveRewardHash from "./resolve-stake-hash";
Expand All @@ -28,6 +29,7 @@ const ReactPage: NextPage = () => {
{ label: "Plutus Script Address", to: "resolvePlutusScriptAddress" },
{ label: "Plutus Script Hash", to: "resolvePlutusScriptHash" },
{ label: "Private Key", to: "resolvePrivateKey" },
{ label: "Script Hash", to: "resolveScriptHash" },
{ label: "Stake Address", to: "resolveRewardAddress" },
{ label: "Stake Key Hash", to: "resolveRewardHash" },
{ label: "Transaction Hash", to: "resolveTxHash" },
Expand Down Expand Up @@ -55,6 +57,7 @@ const ReactPage: NextPage = () => {
<ResolvePlutusScriptAddress />
<ResolvePlutusScriptHash />
<ResolvePrivateKey />
<ResolveScriptHash />
<ResolveRewardAddress />
<ResolveRewardHash />
<ResolveTxHash />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function Left() {
return (
<>
<p>
Provide the Plutus script address, and <code>resolveScriptHash</code>{" "}
will return a script hash. This script hash can be use for building
minting transaction with Plutus contract.
Provide the Plutus script address, and{" "}
<code>resolvePlutusScriptHash</code> will return a script hash. This
script hash can be use for building minting transaction with Plutus
contract.
</p>
</>
);
Expand All @@ -36,8 +37,7 @@ function Right() {
);

async function runDemo() {
const hash = resolvePlutusScriptHash(userInput);
return hash;
return resolvePlutusScriptHash(userInput);
}

let codeSnippet = `resolvePlutusScriptHash('${userInput}')`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { useState } from "react";

import { resolveScriptHash } from "@meshsdk/core";

import Input from "~/components/form/input";
import InputTable from "~/components/sections/input-table";
import LiveCodeDemo from "~/components/sections/live-code-demo";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";

export default function ResolveScriptHash() {
return (
<TwoColumnsScroll
sidebarTo="resolveScriptHash"
title="Resolve Script Hash"
leftSection={Left()}
rightSection={Right()}
/>
);
}

function Left() {
return (
<>
<p>
<code>resolveScriptHash</code> will return a script hash. For example,
this is useful when you want to convert a script to a policy ID.
</p>
</>
);
}

function Right() {
const [userInput, setUserInput] = useState<string>(
"8200581c5867c3b8e27840f556ac268b781578b14c5661fc63ee720dbeab663f",
);

async function runDemo() {
return resolveScriptHash(userInput);
}

let codeSnippet = `resolveScriptHash('${userInput}')`;

return (
<LiveCodeDemo
title="Resolve Script Hash"
subtitle="Convert script to hash (like policy ID)"
code={codeSnippet}
runCodeFunction={runDemo}
>
<InputTable
listInputs={[
<Input
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
label=" script address"
key={0}
/>,
]}
/>
</LiveCodeDemo>
);
}
2 changes: 1 addition & 1 deletion packages/mesh-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/common",
"version": "1.7.1",
"version": "1.7.2",
"description": "",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
12 changes: 6 additions & 6 deletions packages/mesh-contract/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/contract",
"version": "1.7.1",
"version": "1.7.2",
"description": "",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -33,11 +33,11 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@meshsdk/common": "1.7.1",
"@meshsdk/core": "1.7.1",
"@meshsdk/core-csl": "1.7.1",
"@meshsdk/core-cst": "1.7.1",
"@meshsdk/transaction": "1.7.1"
"@meshsdk/common": "1.7.2",
"@meshsdk/core": "1.7.2",
"@meshsdk/core-csl": "1.7.2",
"@meshsdk/core-cst": "1.7.2",
"@meshsdk/transaction": "1.7.2"
},
"prettier": "@meshsdk/configs/prettier",
"publishConfig": {
Expand Down
10 changes: 7 additions & 3 deletions packages/mesh-contract/src/escrow/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
conStr1,
mConStr1,
mConStr2,
MeshValue,
PubKeyAddress,
pubKeyAddress,
Value,
value,
MeshValue
} from "@meshsdk/common";
import {
Asset,
Expand Down Expand Up @@ -68,6 +68,7 @@ export class MeshEscrowContract extends MeshTxInitiator {

constructor(inputs: MeshTxInitiatorInput) {
super(inputs);
this.mesh.setNetwork(inputs.networkId === 1 ? "mainnet" : "preprod");
}

initiateEscrow = async (escrowAmount: Asset[]): Promise<string> => {
Expand Down Expand Up @@ -113,8 +114,11 @@ export class MeshEscrowContract extends MeshTxInitiator {

const initiatorAddress = serializeAddressObj(initiatorAddressObj);
const recipientAddress = serializeAddressObj(recipientAddressObj!);
const initiatorToReceive = MeshValue.fromValue(initiatorAmount).toAssets();
const recipientToReceive = MeshValue.fromValue(recipientAmount!).toAssets();
const initiatorToReceive =
MeshValue.fromValue(initiatorAmount).toAssets();
const recipientToReceive = MeshValue.fromValue(
recipientAmount!,
).toAssets();
this.mesh
.txOut(initiatorAddress, initiatorToReceive)
.txOut(recipientAddress, recipientToReceive);
Expand Down
1 change: 1 addition & 0 deletions packages/mesh-contract/src/giftcard/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class MeshGiftCardContract extends MeshTxInitiator {
if (paramUtxo) {
this.paramUtxo = paramUtxo;
}
this.mesh.setNetwork(inputs.networkId === 1 ? "mainnet" : "preprod");
}

createGiftCard = async (
Expand Down
1 change: 1 addition & 0 deletions packages/mesh-contract/src/hello-world/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class MeshHelloWorldContract extends MeshTxInitiator {

constructor(inputs: MeshTxInitiatorInput) {
super(inputs);
this.mesh.setNetwork(inputs.networkId === 1 ? "mainnet" : "preprod");
}

getScript = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/mesh-contract/src/marketplace/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class MeshMarketplaceContract extends MeshTxInitiator {
],
"JSON",
);
this.mesh.setNetwork(inputs.networkId === 1 ? "mainnet" : "preprod");
}

listAsset = async (asset: string, price: number) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/mesh-contract/src/payment-splitter/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {
"Wallet not provided. Therefore the payment address will not be added to the payees list which makes it impossible to trigger the payout.",
);
}

this.mesh.setNetwork(inputs.networkId === 1 ? "mainnet" : "preprod");
}

sendLovelaceToSplitter = async (lovelaceAmount: number): Promise<string> => {
Expand All @@ -65,7 +67,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {
const { address: scriptAddress } = serializePlutusScript(
script,
undefined,
0,
this.networkId,
);

const { pubKeyHash } = deserializeAddress(walletAddress);
Expand Down Expand Up @@ -100,7 +102,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {
const { address: scriptAddress } = serializePlutusScript(
script,
undefined,
0,
this.networkId,
);
const utxos = (await this.fetcher?.fetchAddressUTxOs(scriptAddress)) || [];
const { pubKeyHash } = deserializeAddress(walletAddress);
Expand Down
3 changes: 2 additions & 1 deletion packages/mesh-contract/src/swap/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export class MeshSwapContract extends MeshTxInitiator {
this.scriptAddress = serializePlutusScript(
{ code: this.scriptCbor, version: "V2" },
undefined,
0,
inputs.networkId,
).address;
this.mesh.setNetwork(inputs.networkId === 1 ? "mainnet" : "preprod");
}

initiateSwap = async (
Expand Down
Loading

0 comments on commit 3d989e6

Please sign in to comment.