Returns a list of used addresses controlled by the wallet.
-
>
);
}
@@ -45,6 +41,10 @@ function Right() {
<>
{hasAvailableWallets && (
+
{walletConnected ? (
<>
amount.
-
>
);
}
@@ -49,6 +45,10 @@ function Right() {
<>
{hasAvailableWallets && (
+
{walletConnected ? (
<>
+
-
+
);
}
diff --git a/packages/demo/components/pages/apis/browserwallet/signData.tsx b/packages/demo/components/pages/apis/browserwallet/signData.tsx
index 58aac4ac7..8787c65c1 100644
--- a/packages/demo/components/pages/apis/browserwallet/signData.tsx
+++ b/packages/demo/components/pages/apis/browserwallet/signData.tsx
@@ -1,12 +1,12 @@
import { useState } from 'react';
import useWallet from '../../../../contexts/wallet';
import Codeblock from '../../../ui/codeblock';
-import SectionTwoCol from '../common/sectionTwoCol';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import Card from '../../../ui/card';
import Input from '../../../ui/input';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import ConnectCipWallet from '../common/connectCipWallet';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import ConnectCipWallet from '../../../common/connectCipWallet';
export default function SignData() {
const [payload, setPayload] = useState('mesh');
@@ -15,16 +15,13 @@ export default function SignData() {
);
}
-function Left(payload) {
- let code = `const addresses = await wallet.getUsedAddresses();\n`;
- code += `const signature = await wallet.signData(addresses[0], '${payload}');`;
-
+function Left() {
return (
<>
@@ -46,7 +43,6 @@ function Left(payload) {
to you as the developer which address you want to use in your
application.
-
>
);
}
@@ -66,6 +62,10 @@ function Right(payload, setPayload) {
setResponse(results);
setLoading(false);
}
+
+ let code = `const addresses = await wallet.getUsedAddresses();\n`;
+ code += `const signature = await wallet.signData(addresses[0], '${payload}');`;
+
return (
+
{hasAvailableWallets && (
<>
{walletConnected ? (
diff --git a/packages/demo/components/pages/apis/browserwallet/signTx.tsx b/packages/demo/components/pages/apis/browserwallet/signTx.tsx
index 09ef1dc04..7aadf2e35 100644
--- a/packages/demo/components/pages/apis/browserwallet/signTx.tsx
+++ b/packages/demo/components/pages/apis/browserwallet/signTx.tsx
@@ -1,6 +1,7 @@
import Link from 'next/link';
import Codeblock from '../../../ui/codeblock';
-import SectionTwoCol from '../common/sectionTwoCol';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import Card from '../../../ui/card';
export default function SignTx() {
return (
@@ -17,21 +18,27 @@ function Left() {
return (
<>
- Requests user to sign the provided transaction. The wallet should ask
- the user for permission, and if given, try to sign the supplied body and
- return a signed transaction. partialSign should be{' '}
- true if the transaction provided requires multiple
- signatures. Check out Transaction{' '}
- to learn more on how to use this API.
+ Requests user to sign the provided transaction (tx). The
+ wallet should ask the user for permission, and if given, try to sign the
+ supplied body and return a signed transaction. partialSign{' '}
+ should be true if the transaction provided requires
+ multiple signatures.
+ Check out Transaction to learn
+ more on how to use this API.
+
+
+ );
}
diff --git a/packages/demo/components/pages/apis/browserwallet/submitTx.tsx b/packages/demo/components/pages/apis/browserwallet/submitTx.tsx
index d0c1250d8..f3c5cd428 100644
--- a/packages/demo/components/pages/apis/browserwallet/submitTx.tsx
+++ b/packages/demo/components/pages/apis/browserwallet/submitTx.tsx
@@ -1,6 +1,7 @@
import Link from 'next/link';
import Codeblock from '../../../ui/codeblock';
-import SectionTwoCol from '../common/sectionTwoCol';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import Card from '../../../ui/card';
export default function SubmitTransaction() {
return (
@@ -21,18 +22,23 @@ function Left() {
allow dApps to request that a transaction be sent through it. If the
wallet accepts the transaction and tries to send it, it shall return the
transaction ID for the dApp to track. The wallet can return error
- messages or failure if there was an error in sending it. Check out{' '}
- Transaction to learn more on how
- to use this API.
+ messages or failure if there was an error in sending it.
-
>
);
}
function Right() {
- return <>>;
+ return (
+
+
+
+ Check out Transaction to learn
+ more on how to use this API.
+
+ Fetch UTXOs in the provided address. Optionally, you can
+ filter UTXOs containing a particular asset by providing{' '}
+ asset, where it is the concatenation of policy ID and
+ asset.
+
- Helpful functions that you need while building dApps
+ Helpful functions for converting Cardano objects
{/*
diff --git a/packages/demo/components/pages/apis/resolvers/index.tsx b/packages/demo/components/pages/apis/resolvers/index.tsx
index 5ecd25628..bdab19d64 100644
--- a/packages/demo/components/pages/apis/resolvers/index.tsx
+++ b/packages/demo/components/pages/apis/resolvers/index.tsx
@@ -1,52 +1,39 @@
-import ApisLayout from '../common/layout';
+import CommonLayout from '../../../common/layout';
import ResolveDataHash from './resolveDataHash';
import Hero from './hero';
import ResolveFingerprint from './resolveFingerprint';
import ResolvePrivateKey from './resolvePrivateKey';
-import ResolveScriptAddress from './resolveScriptAddress';
-import ResolveScriptHash from './resolveScriptHash';
+import ResolvePlutusScriptAddress from './resolvePlutusScriptAddress';
+import ResolvePlutusScriptHash from './resolvePlutusScriptHash';
import ResolvePaymentKeyHash from './resolvePaymentKeyHash';
import ResolveStakeAddress from './resolveStakeAddress';
import ResolveStakeKeyHash from './resolveStakeKeyHash';
import ResolveTxHash from './resolveTxHash';
+import ResolveEpochNo from './resolveEpochNo';
+import ResolveSlotNo from './resolveSlotNo';
+import ResolveNativeScriptHash from './resolveNativeScriptHash';
export default function Resolvers() {
const sidebarItems = [
{ label: 'Data Hash', to: 'resolveDataHash' },
{ label: 'Fingerprint', to: 'resolveFingerprint' },
+ { label: 'Native Script Hash', to: 'resolveNativeScriptHash' },
{ label: 'Payment Key Hash', to: 'resolvePaymentKeyHash' },
+ { label: 'Plutus Script Address', to: 'resolvePlutusScriptAddress' },
+ { label: 'Plutus Script Hash', to: 'resolvePlutusScriptHash' },
{ label: 'Private Key', to: 'resolvePrivateKey' },
- { label: 'Script Address', to: 'resolveScriptAddress' },
- { label: 'Script Hash', to: 'resolveScriptHash' },
{ label: 'Stake Address', to: 'resolveStakeAddress' },
{ label: 'Stake Key Hash', to: 'resolveStakeKeyHash' },
{ label: 'Tx Hash', to: 'resolveTxHash' },
+ { label: 'Slot Number', to: 'resolveSlotNo' },
+ { label: 'Epoch Number', to: 'resolveEpochNo' },
];
- // resolveDataHash
- // - you give it a Data object it will calculate the hash
- // resolveFingerprint
- // - you give it an Asset object it will calculate the asset fingerprint CIP-5
- // resolvePaymentKeyHash
- // - you give it a bech32 address long aka base address/payment address or short one aka enterprise address it will return the pub key hash of the payment key
- // resolvePrivateKey
- // - you give the 24 words aka mnemonic it will return a bech32 private key
- // resolveScriptAddress
- // - you give it a plutus script cbor hex it will give you the address for it
- // resolveScriptHash
- // - you give it the plutus script address it will give you the script hash
- // resolveStakeAddress
- // - you give it a base address inbech32 format it will return a stake address
- // resolveStakeKeyHash
- // - you give it a bech32 address long aka base address/payment address or short one aka rewards address starts with stake it will return the pub key hash of the stake key
- // resolveTxHash
- // - you give it a cbor transaction it will give you the hash of the transaction
-
return (
-
+
-
+
);
}
@@ -55,13 +42,16 @@ function Main() {
<>
+
+
+
-
-
+
+
>
);
}
diff --git a/packages/demo/components/pages/apis/resolvers/resolveDataHash.tsx b/packages/demo/components/pages/apis/resolvers/resolveDataHash.tsx
index 456ca7ffa..a42d0a0fe 100644
--- a/packages/demo/components/pages/apis/resolvers/resolveDataHash.tsx
+++ b/packages/demo/components/pages/apis/resolvers/resolveDataHash.tsx
@@ -1,9 +1,9 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import SectionTwoCol from '../common/sectionTwoCol';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
import { resolveDataHash } from '@martifylabs/mesh';
import type { Data } from '@martifylabs/mesh';
import Input from '../../../ui/input';
diff --git a/packages/demo/components/pages/apis/resolvers/resolveEpochNo.tsx b/packages/demo/components/pages/apis/resolvers/resolveEpochNo.tsx
new file mode 100644
index 000000000..feb9e64b3
--- /dev/null
+++ b/packages/demo/components/pages/apis/resolvers/resolveEpochNo.tsx
@@ -0,0 +1,98 @@
+import { useState } from 'react';
+import Codeblock from '../../../ui/codeblock';
+import Card from '../../../ui/card';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import { resolveEpochNo } from '@martifylabs/mesh';
+import Select from '../../../ui/select';
+
+export default function ResolveEpochNo() {
+ const [userinput, setUserinput] = useState('mainnet');
+
+ return (
+
+ );
+}
+
+function Left(userinput) {
+ let code1 = `import { resolveEpochNo } from '@martifylabs/mesh';\n`;
+
+ let code2 = `${code1}const epoch = resolveEpochNo('${userinput}');`;
+
+ let code3 = `${code1}`;
+ code3 += `let oneYearFromNow = new Date();\n`;
+ code3 += `oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);\n`;
+ code3 += `const epoch = resolveEpochNo('${userinput}', oneYearFromNow.getTime());`;
+
+ return (
+ <>
+
+ With resolveEpochNo, you can get the current epoch with:
+
+
+
+ You can also provide date in milliseconds to get epoch in
+ the past or the future. For example, get the epoch 1 year from now:
+
+
+ >
+ );
+}
+
+function Right(userinput, setUserinput, userinput2, setUserinput2) {
+ const [loading, setLoading] = useState(false);
+ const [response, setResponse] = useState(null);
+ const [responseError, setResponseError] = useState(null);
+
+ async function runDemo() {
+ setLoading(true);
+ setResponse(null);
+ setResponseError(null);
+
+ try {
+ const keyHash = resolvePaymentKeyHash(userinput);
+
+ let oneYearFromNow = new Date();
+ oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
+ const slot = resolveSlotNo('mainnet', oneYearFromNow.getTime());
+
+ const nativeScript: NativeScript = {
+ type: 'all',
+ scripts: [
+ {
+ type: 'before',
+ slot: slot,
+ },
+ {
+ type: 'sig',
+ keyHash: keyHash,
+ },
+ ],
+ };
+
+ const hash = resolveNativeScriptHash(nativeScript);
+ setResponse(hash);
+ } catch (error) {
+ setResponseError(`${error}`);
+ }
+ setLoading(false);
+ }
+
+ return (
+ <>
+
+ setUserinput(e.target.value)}
+ placeholder="Address"
+ label="Address"
+ />
+
+
+
+
+ >
+ );
+}
diff --git a/packages/demo/components/pages/apis/resolvers/resolvePaymentKeyHash.tsx b/packages/demo/components/pages/apis/resolvers/resolvePaymentKeyHash.tsx
index f4c39ad58..67447a08a 100644
--- a/packages/demo/components/pages/apis/resolvers/resolvePaymentKeyHash.tsx
+++ b/packages/demo/components/pages/apis/resolvers/resolvePaymentKeyHash.tsx
@@ -1,9 +1,9 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import SectionTwoCol from '../common/sectionTwoCol';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
import { resolvePaymentKeyHash } from '@martifylabs/mesh';
import Input from '../../../ui/input';
import { demoAddresses } from '../../../../configs/demo';
diff --git a/packages/demo/components/pages/apis/resolvers/resolveScriptAddress.tsx b/packages/demo/components/pages/apis/resolvers/resolvePlutusScriptAddress.tsx
similarity index 64%
rename from packages/demo/components/pages/apis/resolvers/resolveScriptAddress.tsx
rename to packages/demo/components/pages/apis/resolvers/resolvePlutusScriptAddress.tsx
index 5412ff3f7..23ac9df7e 100644
--- a/packages/demo/components/pages/apis/resolvers/resolveScriptAddress.tsx
+++ b/packages/demo/components/pages/apis/resolvers/resolvePlutusScriptAddress.tsx
@@ -1,13 +1,14 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import SectionTwoCol from '../common/sectionTwoCol';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import { resolveScriptAddress } from '@martifylabs/mesh';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import { resolvePlutusScriptAddress } from '@martifylabs/mesh';
import Input from '../../../ui/input';
+import type { PlutusScript } from '@martifylabs/mesh';
-export default function ResolveScriptAddress() {
+export default function ResolvePlutusScriptAddress() {
const [userinput, setUserinput] = useState(0);
const [userinput2, setUserinput2] = useState(
'4e4d01000033222220051200120011'
@@ -15,7 +16,7 @@ export default function ResolveScriptAddress() {
return (
- Provide the Plutus script in CBOR, and resolveScriptAddress{' '}
- will return a bech32 address of the script.
+ Provide the Plutus script in CBOR, and{' '}
+ resolvePlutusScriptAddress will return a bech32 address of
+ the script.
For example, we can get the address of the always succeed{' '}
@@ -51,7 +61,11 @@ function Right(userinput, setUserinput, userinput2, setUserinput2) {
setResponse(null);
setResponseError(null);
try {
- const hash = resolveScriptAddress(userinput, userinput2);
+ const script: PlutusScript = {
+ code: userinput2,
+ version: 'V1',
+ };
+ const hash = resolvePlutusScriptAddress(script, userinput);
setResponse(hash);
} catch (error) {
setResponseError(`${error}`);
diff --git a/packages/demo/components/pages/apis/resolvers/resolveScriptHash.tsx b/packages/demo/components/pages/apis/resolvers/resolvePlutusScriptHash.tsx
similarity index 75%
rename from packages/demo/components/pages/apis/resolvers/resolveScriptHash.tsx
rename to packages/demo/components/pages/apis/resolvers/resolvePlutusScriptHash.tsx
index 8a0abcd21..1ffc77c2d 100644
--- a/packages/demo/components/pages/apis/resolvers/resolveScriptHash.tsx
+++ b/packages/demo/components/pages/apis/resolvers/resolvePlutusScriptHash.tsx
@@ -1,21 +1,21 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import SectionTwoCol from '../common/sectionTwoCol';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import { resolveScriptHash } from '@martifylabs/mesh';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import { resolvePlutusScriptHash } from '@martifylabs/mesh';
import Input from '../../../ui/input';
-export default function ResolveScriptHash() {
+export default function ResolvePlutusScriptHash() {
const [userinput, setUserinput] = useState(
'addr_test1wpnlxv2xv9a9ucvnvzqakwepzl9ltx7jzgm53av2e9ncv4sysemm8'
);
return (
@@ -23,7 +23,7 @@ export default function ResolveScriptHash() {
}
function Left(userinput) {
- let code = `import { resolveScriptHash } from '@martifylabs/mesh';\nconst hash = resolveScriptHash('${userinput}');`;
+ let code = `import { resolvePlutusScriptHash } from '@martifylabs/mesh';\nconst hash = resolvePlutusScriptHash('${userinput}');`;
return (
<>
@@ -47,7 +47,7 @@ function Right(userinput, setUserinput) {
setResponse(null);
setResponseError(null);
try {
- const hash = resolveScriptHash(userinput);
+ const hash = resolvePlutusScriptHash(userinput);
setResponse(hash);
} catch (error) {
setResponseError(`${error}`);
diff --git a/packages/demo/components/pages/apis/resolvers/resolvePrivateKey.tsx b/packages/demo/components/pages/apis/resolvers/resolvePrivateKey.tsx
index 671748b0e..43879c738 100644
--- a/packages/demo/components/pages/apis/resolvers/resolvePrivateKey.tsx
+++ b/packages/demo/components/pages/apis/resolvers/resolvePrivateKey.tsx
@@ -1,9 +1,9 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import SectionTwoCol from '../common/sectionTwoCol';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
import { resolvePrivateKey } from '@martifylabs/mesh';
import { demoMnemonic } from '../../../../configs/demo';
import Textarea from '../../../ui/textarea';
diff --git a/packages/demo/components/pages/apis/resolvers/resolveSlotNo.tsx b/packages/demo/components/pages/apis/resolvers/resolveSlotNo.tsx
new file mode 100644
index 000000000..2e44a2897
--- /dev/null
+++ b/packages/demo/components/pages/apis/resolvers/resolveSlotNo.tsx
@@ -0,0 +1,100 @@
+import { useState } from 'react';
+import Codeblock from '../../../ui/codeblock';
+import Card from '../../../ui/card';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import { resolveSlotNo } from '@martifylabs/mesh';
+import Select from '../../../ui/select';
+
+export default function ResolveSlotNo() {
+ const [userinput, setUserinput] = useState('mainnet');
+
+ return (
+
+ );
+}
+
+function Left(userinput) {
+ let code1 = `import { resolveSlotNo } from '@martifylabs/mesh';\n`;
+
+ let code2 = `${code1}const slot = resolveSlotNo('${userinput}');`;
+
+ let code3 = `${code1}`;
+ code3 += `let oneYearFromNow = new Date();\n`;
+ code3 += `oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);\n`;
+ code3 += `const slot = resolveSlotNo('${userinput}', oneYearFromNow.getTime());`;
+
+ return (
+ <>
+
+ With resolveSlotNo, you can get the current slot number
+ with:
+
+
+
+ You can also provide date in milliseconds to get slots in
+ the past or the future. For example, get the slot number 1 year from
+ now:
+
+
+ >
+ );
+}
+
+function Right(userinput, setUserinput) {
+ const [loading, setLoading] = useState(false);
+ const [response, setResponse] = useState(null);
+ const [responseError, setResponseError] = useState(null);
+
+ const networks = {
+ mainnet: 'Mainnet',
+ preprod: 'Preprod',
+ preview: 'Preview',
+ testnet: 'Testnet',
+ };
+
+ async function runDemo() {
+ setLoading(true);
+ setResponse(null);
+ setResponseError(null);
+
+ // let oneYearFromNow = new Date();
+ // oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
+ // const slot = resolveSlotNo('mainnet', oneYearFromNow.getTime());
+
+ try {
+ const slot = resolveSlotNo(userinput);
+ setResponse(slot);
+ } catch (error) {
+ setResponseError(`${error}`);
+ }
+ setLoading(false);
+ }
+
+ return (
+ <>
+
+
+ >
+ );
+}
diff --git a/packages/demo/components/pages/apis/resolvers/resolveStakeAddress.tsx b/packages/demo/components/pages/apis/resolvers/resolveStakeAddress.tsx
index defeeca4d..d27767917 100644
--- a/packages/demo/components/pages/apis/resolvers/resolveStakeAddress.tsx
+++ b/packages/demo/components/pages/apis/resolvers/resolveStakeAddress.tsx
@@ -1,9 +1,9 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import SectionTwoCol from '../common/sectionTwoCol';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
import { resolveStakeAddress } from '@martifylabs/mesh';
import Input from '../../../ui/input';
diff --git a/packages/demo/components/pages/apis/resolvers/resolveStakeKeyHash.tsx b/packages/demo/components/pages/apis/resolvers/resolveStakeKeyHash.tsx
index b54af1c6e..ba82f66eb 100644
--- a/packages/demo/components/pages/apis/resolvers/resolveStakeKeyHash.tsx
+++ b/packages/demo/components/pages/apis/resolvers/resolveStakeKeyHash.tsx
@@ -1,9 +1,9 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import SectionTwoCol from '../common/sectionTwoCol';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
import { resolveStakeKeyHash } from '@martifylabs/mesh';
import Input from '../../../ui/input';
diff --git a/packages/demo/components/pages/apis/resolvers/resolveTxHash.tsx b/packages/demo/components/pages/apis/resolvers/resolveTxHash.tsx
index fd12221d9..66dfe8709 100644
--- a/packages/demo/components/pages/apis/resolvers/resolveTxHash.tsx
+++ b/packages/demo/components/pages/apis/resolvers/resolveTxHash.tsx
@@ -1,9 +1,9 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import SectionTwoCol from '../common/sectionTwoCol';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
import {
resolveTxHash,
Transaction,
diff --git a/packages/demo/components/pages/apis/transaction/burning.tsx b/packages/demo/components/pages/apis/transaction/burning.tsx
index 5f0fe2c17..9c55d4570 100644
--- a/packages/demo/components/pages/apis/transaction/burning.tsx
+++ b/packages/demo/components/pages/apis/transaction/burning.tsx
@@ -1,11 +1,11 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import SectionTwoCol from '../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import useWallet from '../../../../contexts/wallet';
-import ConnectCipWallet from '../common/connectCipWallet';
+import ConnectCipWallet from '../../../common/connectCipWallet';
import Input from '../../../ui/input';
import { Transaction, ForgeScript } from '@martifylabs/mesh';
import type { Asset, AssetExtended } from '@martifylabs/mesh';
diff --git a/packages/demo/components/pages/apis/transaction/coinSelection.tsx b/packages/demo/components/pages/apis/transaction/coinSelection.tsx
new file mode 100644
index 000000000..b04e3c87e
--- /dev/null
+++ b/packages/demo/components/pages/apis/transaction/coinSelection.tsx
@@ -0,0 +1,150 @@
+import { useEffect, useState } from 'react';
+import Codeblock from '../../../ui/codeblock';
+import Card from '../../../ui/card';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+import useWallet from '../../../../contexts/wallet';
+import ConnectCipWallet from '../../../common/connectCipWallet';
+import Input from '../../../ui/input';
+import Button from '../../../ui/button';
+import { PlusCircleIcon, TrashIcon } from '@heroicons/react/24/solid';
+import { largestFirstMultiAsset } from '@martifylabs/mesh';
+import type { Unit, Quantity } from '@martifylabs/mesh';
+
+export default function CoinSelection() {
+ return (
+
+ );
+}
+
+function Left() {
+ let codeSnippet1 = `import { largestFirst } from '@martifylabs/mesh';\n\n`;
+ codeSnippet1 += `const utxos = await wallet.getUtxos();\n\n`;
+ codeSnippet1 += `const costLovelace = '10000000';\n`;
+ codeSnippet1 += `const selectedUtxos = largestFirst(costLovelace, utxos, true);`;
+
+ let codeSnippet2 = `import { largestFirstMultiAsset } from '@martifylabs/mesh';\n`;
+ codeSnippet2 += `import type { Unit, Quantity } from '@martifylabs/mesh';\n\n`;
+ codeSnippet2 += `const utxos = await wallet.getUtxos();\n\n`;
+ codeSnippet2 += `const assetMap = new Map();\n`;
+ codeSnippet2 += `assetMap.set(\n`;
+ codeSnippet2 += ` 'd9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e',\n`;
+ codeSnippet2 += ` '1'\n`;
+ codeSnippet2 += `);\n`;
+ codeSnippet2 += `// if you need to include lovelace\n`;
+ codeSnippet2 += `assetMap.set(\n`;
+ codeSnippet2 += ` 'lovelace',\n`;
+ codeSnippet2 += ` '10000000'\n`;
+ codeSnippet2 += `);\n`;
+ codeSnippet2 += `// if you need to include more than 1 native asset\n`;
+ codeSnippet2 += `assetMap.set(\n`;
+ codeSnippet2 += ` 'another asset unit',\n`;
+ codeSnippet2 += ` '1'\n`;
+ codeSnippet2 += `);\n\n`;
+ codeSnippet2 += `const selectedUtxos = largestFirstMultiAsset(assetMap, utxos, true);`;
+
+ let code3 = ``;
+ code3 += `largestFirst = (\n`;
+ code3 += ` lovelace: Quantity, initialUTxOSet: UTxO[], includeTxFees = false,\n`;
+ code3 += ` { maxTxSize, minFeeA, minFeeB } = DEFAULT_PROTOCOL_PARAMETERS,\n`;
+ code3 += `): UTxO[]`;
+ let code4 = ``;
+ code4 += `largestFirstMultiAsset = (\n`;
+ code4 += ` requestedOutputSet: Map, initialUTxOSet: UTxO[],\n`;
+ code4 += ` includeTxFees = false, parameters = DEFAULT_PROTOCOL_PARAMETERS,\n`;
+ code4 += `): UTxO[]\n`;
+
+ return (
+ <>
+
+ There are two coin selection algorithm, one for selecting lovelace,
+ another for selecting multiple assets.
+
+
+ To select UTXOs for transaction that only requires lovelace, use{' '}
+ largestFirst.
+
+
+
For example, selecting the UTXOs for sending 10000000 lovelace:
+
+
+ largestFirstMultiAsset allows you to select native assets
+ by defining a Map of required assets.
+
+
+
+ Although you have use this to specify require lovelace to fulfill this
+ transaction, but if your transaction only required lovelace, the
+ algorithm will exclude all multiasset utxo from the selection, thus you
+ could select the required UTXOs more efficiently.
+
+
+
+ The third parameter, includeTxFees, if True,
+ Mesh will calculate the fees required, and include additional UTXOs to
+ fulfill the fees amount.
+
+ >
+ );
+}
+
+function Right() {
+ const [state, setState] = useState(0);
+ const [response, setResponse] = useState(null);
+ const [responseError, setResponseError] = useState(null);
+ const { wallet, walletConnected, hasAvailableWallets } = useWallet();
+
+ async function runDemo() {
+ setState(1);
+ setResponseError(null);
+
+ const utxos = await wallet.getUtxos();
+ console.log('all utxos', utxos);
+ const assetMap = new Map();
+ assetMap.set(
+ 'd9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e',
+ // '64af286e2ad0df4de2e7de15f8ff5b3d27faecf4ab2757056d860a424d657368546f6b656e',
+ '1'
+ );
+ // assetMap.set(
+ // 'lovelace',
+ // '10000000'
+ // );
+ const selectedUtxos = largestFirstMultiAsset(assetMap, utxos, true);
+ console.log('selectedUtxos', selectedUtxos);
+
+ try {
+ setState(2);
+ } catch (error) {
+ setResponseError(`${error}`);
+ setState(0);
+ }
+ }
+
+ return (
+
+ {hasAvailableWallets && (
+ <>
+ {walletConnected ? (
+ <>
+
+
+ >
+ ) : (
+
+ )}
+ >
+ )}
+
+ );
+}
diff --git a/packages/demo/components/pages/apis/transaction/datum.tsx b/packages/demo/components/pages/apis/transaction/datum.tsx
index 9ef365143..69e7bf40c 100644
--- a/packages/demo/components/pages/apis/transaction/datum.tsx
+++ b/packages/demo/components/pages/apis/transaction/datum.tsx
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
-import SectionTwoCol from '../common/sectionTwoCol';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import { resolveDataHash } from '@martifylabs/mesh';
import type { Data } from '@martifylabs/mesh';
diff --git a/packages/demo/components/pages/apis/transaction/getSize.tsx b/packages/demo/components/pages/apis/transaction/getSize.tsx
index 40750990a..07d3b6dbb 100644
--- a/packages/demo/components/pages/apis/transaction/getSize.tsx
+++ b/packages/demo/components/pages/apis/transaction/getSize.tsx
@@ -1,11 +1,9 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import SectionTwoCol from '../common/sectionTwoCol';
-import useWallet from '../../../../contexts/wallet';
-import ConnectCipWallet from '../common/connectCipWallet';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import Input from '../../../ui/input';
import Button from '../../../ui/button';
import { PlusCircleIcon, TrashIcon } from '@heroicons/react/24/solid';
diff --git a/packages/demo/components/pages/apis/transaction/index.tsx b/packages/demo/components/pages/apis/transaction/index.tsx
index cf7f339a2..9a6f28fc9 100644
--- a/packages/demo/components/pages/apis/transaction/index.tsx
+++ b/packages/demo/components/pages/apis/transaction/index.tsx
@@ -1,12 +1,13 @@
-import ApisLayout from '../common/layout';
+import CommonLayout from '../../../common/layout';
import Burning from './burning';
+import CoinSelection from './coinSelection';
import DesignDatum from './datum';
-// import GetSize from './getSize';
import Hero from './hero';
import LockAssets from './lockAssets';
import Minting from './minting';
import SendAda from './sendAda';
import SendAssets from './sendAssets';
+import SetTimeLimit from './setTimeLimit';
import UnlockAssets from './unlockAssets';
import UsingRedeemer from './redeemer';
@@ -20,13 +21,15 @@ export default function Transaction() {
{ label: 'Unlock assets on smart contract', to: 'unlockAssets' },
{ label: 'Designing datum', to: 'datum' },
{ label: 'Using redeemer', to: 'redeemer' },
+ { label: 'Set time limit', to: 'setTimeLimit' },
+ { label: 'Coin Selection', to: 'coinSelection' },
];
return (
-
+
-
+
);
}
@@ -39,9 +42,10 @@ function Main() {
- {/* */}
+
+
>
);
}
diff --git a/packages/demo/components/pages/apis/transaction/lockAssets.tsx b/packages/demo/components/pages/apis/transaction/lockAssets.tsx
index 049104e2a..1ecf9f1a6 100644
--- a/packages/demo/components/pages/apis/transaction/lockAssets.tsx
+++ b/packages/demo/components/pages/apis/transaction/lockAssets.tsx
@@ -1,14 +1,14 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import SectionTwoCol from '../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import useWallet from '../../../../contexts/wallet';
-import ConnectCipWallet from '../common/connectCipWallet';
+import ConnectCipWallet from '../../../common/connectCipWallet';
import Input from '../../../ui/input';
import { Transaction, Asset } from '@martifylabs/mesh';
-import FetchSelectAssets from '../common/fetchSelectAssets';
+import FetchSelectAssets from '../../../common/fetchSelectAssets';
// always succeed
const script = '4e4d01000033222220051200120011';
@@ -80,17 +80,25 @@ function Left({ userInput, inputDatum }) {
return assetId != 'lovelace';
});
if (nativeAssets.length) {
- codeSnippet += `\n .sendAssets(\n "${scriptAddress}",`;
- codeSnippet += `\n [`;
+ // codeSnippet += `\n .sendAssets(\n "${scriptAddress}",`;
+
+ codeSnippet += `\n`;
+ codeSnippet += ` .sendAssets(\n`;
+ codeSnippet += ` {\n`;
+ codeSnippet += ` address: scriptAddress,\n`;
+ codeSnippet += ` datum: {\n`;
+ codeSnippet += ` value: '${inputDatum}',\n`;
+ codeSnippet += ` },\n`;
+ codeSnippet += ` },\n`;
+ codeSnippet += ` [`;
for (const asset of nativeAssets) {
codeSnippet += `\n {`;
codeSnippet += `\n unit: "${asset}",`;
codeSnippet += `\n quantity: "1",`;
- codeSnippet += `\n },`;
+ codeSnippet += `\n },\n`;
}
- codeSnippet += `\n ],\n`;
- codeSnippet += ` { datum: '${inputDatum}' }`;
- codeSnippet += `\n )`;
+ codeSnippet += ` ],\n`;
+ codeSnippet += ` )`;
}
}
codeSnippet += `;\n`;
@@ -144,10 +152,24 @@ function Right({ userInput, updateField, inputDatum, setInputDatum }) {
})
);
+ if (assets.length == 0) {
+ setState(0);
+ setResponseError(`No assets selected for locking.`);
+ return;
+ }
+
console.log(111, Object.keys(userInput[0].assets)[0]);
updateUserStorage('lockedAssetUnit', Object.keys(userInput[0].assets)[0]);
+ tx.sendAssets(
+ {
+ address: scriptAddress,
+ datum: {
+ value: inputDatum,
+ },
+ },
+ assets
+ );
- tx.sendAssets(scriptAddress, assets, { datum: inputDatum });
const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);
@@ -204,7 +226,7 @@ function InputTable({ userInput, updateField, inputDatum, setInputDatum }) {
Lock assets in smart contract
Define a datum and select assets to lock in smart contract. Note:
- this demo only works on preview network.
+ this demo only works on preprod network.
diff --git a/packages/demo/components/pages/apis/transaction/minting.tsx b/packages/demo/components/pages/apis/transaction/minting.tsx
index 3931feec9..22734aabe 100644
--- a/packages/demo/components/pages/apis/transaction/minting.tsx
+++ b/packages/demo/components/pages/apis/transaction/minting.tsx
@@ -1,11 +1,11 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import SectionTwoCol from '../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import useWallet from '../../../../contexts/wallet';
-import ConnectCipWallet from '../common/connectCipWallet';
+import ConnectCipWallet from '../../../common/connectCipWallet';
import Input from '../../../ui/input';
import Button from '../../../ui/button';
import { PlusCircleIcon, TrashIcon } from '@heroicons/react/24/solid';
@@ -54,7 +54,7 @@ export default function Minting() {
quantity: 1,
});
} else if (action == 'update') {
- if (value >= 1 || field == 'metadata') {
+ if (value >= 1 || field == 'metadata' || field == 'assetName') {
updated[index][field] = value;
}
} else if (action == 'remove') {
@@ -121,9 +121,7 @@ function Left({ userInput }) {
codeSnippet += ` assetQuantity: '${recipient.quantity}',\n`;
codeSnippet += ` metadata: assetMetadata${counter},\n`;
codeSnippet += ` label: '${recipient.assetLabel}',\n`;
- codeSnippet += ` recipient: {\n`;
- codeSnippet += ` address: '${recipient.address}',\n`;
- codeSnippet += ` },\n`;
+ codeSnippet += ` recipient: '${recipient.address}',\n`;
codeSnippet += `};\n`;
codeSnippet += `tx.mintAsset(\n`;
codeSnippet += ` forgingScript,\n`;
@@ -150,9 +148,7 @@ function Left({ userInput }) {
codeSnippet2 += ` assetQuantity: '1',\n`;
codeSnippet2 += ` metadata: assetMetadata,\n`;
codeSnippet2 += ` label: '721',\n`;
- codeSnippet2 += ` recipient: {\n`;
- codeSnippet2 += ` address: '${demoAddresses.testnet}',\n`;
- codeSnippet2 += ` },\n`;
+ codeSnippet2 += ` recipient: '${demoAddresses.testnet}' \n`;
codeSnippet2 += `};\n`;
codeSnippet2 += `tx.mintAsset(\n`;
codeSnippet2 += ` forgingScript,\n`;
@@ -192,14 +188,15 @@ function Left({ userInput }) {
Here is the full code:
- Additionally, you can include NativeScript to define the
- forging script (for example if you want to have a policy locking
- script), you can do this:
+ Additionally, you can define the forging script with{' '}
+ NativeScript. For example if you want to have a policy
+ locking script, you can do this:
- As for the keyHash, you can get it using{' '}
- resolvePaymentKeyHash, see{' '}
+ You can get the keyHash with{' '}
+ resolvePaymentKeyHash. As for slot, get it
+ using resolveSlotNo. See{' '}
Resolvers.
>
@@ -242,9 +239,7 @@ function Right({ userInput, updateField }) {
assetQuantity: recipient.quantity.toString(),
metadata: assetMetadata,
label: recipient.assetLabel,
- recipient: {
- address: recipient.address,
- },
+ recipient: recipient.address,
};
tx.mintAsset(forgingScript, asset);
}
diff --git a/packages/demo/components/pages/apis/transaction/redeemer.tsx b/packages/demo/components/pages/apis/transaction/redeemer.tsx
index 3bf8da550..0fe81231e 100644
--- a/packages/demo/components/pages/apis/transaction/redeemer.tsx
+++ b/packages/demo/components/pages/apis/transaction/redeemer.tsx
@@ -1,8 +1,6 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
-import SectionTwoCol from '../common/sectionTwoCol';
-import { resolveDataHash } from '@martifylabs/mesh';
-import type { Data } from '@martifylabs/mesh';
+import SectionTwoCol from '../../../common/sectionTwoCol';
export default function UsingRedeemer() {
return (
diff --git a/packages/demo/components/pages/apis/transaction/sendAda.tsx b/packages/demo/components/pages/apis/transaction/sendAda.tsx
index 640cb5022..18198b9cc 100644
--- a/packages/demo/components/pages/apis/transaction/sendAda.tsx
+++ b/packages/demo/components/pages/apis/transaction/sendAda.tsx
@@ -1,11 +1,11 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import SectionTwoCol from '../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import useWallet from '../../../../contexts/wallet';
-import ConnectCipWallet from '../common/connectCipWallet';
+import ConnectCipWallet from '../../../common/connectCipWallet';
import Input from '../../../ui/input';
import Button from '../../../ui/button';
import { PlusCircleIcon, TrashIcon } from '@heroicons/react/24/solid';
@@ -80,9 +80,12 @@ export default function SendAda() {
}
function Left({ userInput }) {
- let codeSnippet = `const tx = new Transaction({ initiator: wallet });`;
+ let codeSnippet = `const tx = new Transaction({ initiator: wallet })\n`;
for (const recipient of userInput) {
- codeSnippet += `\ntx.sendLovelace(\n '${recipient.address}',\n '${recipient.assets.lovelace}'\n)`;
+ codeSnippet += ` .sendLovelace(\n`;
+ codeSnippet += ` '${recipient.address}',\n`;
+ codeSnippet += ` '${recipient.assets.lovelace}'\n`;
+ codeSnippet += ` )\n`;
}
codeSnippet += `;\n`;
codeSnippet += `const unsignedTx = await tx.build();\n`;
@@ -126,7 +129,7 @@ function Right({ userInput, updateField }) {
for (const recipient of userInput) {
if (recipient.assets.lovelace) {
tx.sendLovelace(
- recipient.address,
+ { address: recipient.address },
recipient.assets.lovelace.toString()
);
}
diff --git a/packages/demo/components/pages/apis/transaction/sendAssets.tsx b/packages/demo/components/pages/apis/transaction/sendAssets.tsx
index 527ad3db0..3222f37d7 100644
--- a/packages/demo/components/pages/apis/transaction/sendAssets.tsx
+++ b/packages/demo/components/pages/apis/transaction/sendAssets.tsx
@@ -1,16 +1,16 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import SectionTwoCol from '../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import useWallet from '../../../../contexts/wallet';
-import ConnectCipWallet from '../common/connectCipWallet';
+import ConnectCipWallet from '../../../common/connectCipWallet';
import Input from '../../../ui/input';
import Button from '../../../ui/button';
import { PlusCircleIcon, TrashIcon } from '@heroicons/react/24/solid';
import { demoAddresses } from '../../../../configs/demo';
-import FetchSelectAssets from '../common/fetchSelectAssets';
+import FetchSelectAssets from '../../../common/fetchSelectAssets';
import { Transaction } from '@martifylabs/mesh';
import type { Asset } from '@martifylabs/mesh';
@@ -117,7 +117,8 @@ function Left({ userInput }) {
codeSnippet += `const signedTx = await wallet.signTx(unsignedTx);\n`;
codeSnippet += `const txHash = await wallet.submitTx(signedTx);`;
- let codeSnippet1 = `let assets: Asset[] = [];\n`;
+ let codeSnippet1 = `import type { Asset } from '@martifylabs/mesh';\n\n`;
+ codeSnippet1 += `let assets: Asset[] = [];\n`;
codeSnippet1 += `for (const asset of nativeAssets) {\n`;
codeSnippet1 += ` let thisAsset = {\n`;
codeSnippet1 += ` unit: '64af286e2ad0df4de2e7de15f8ff5b3d27faecf4ab2757056d860a424d657368546f6b656e',\n`;
@@ -159,7 +160,7 @@ function Right({ userInput, updateField }) {
for (const recipient of userInput) {
if (recipient.assets.lovelace) {
tx.sendLovelace(
- recipient.address,
+ { address: recipient.address },
recipient.assets.lovelace.toString()
);
}
@@ -175,7 +176,7 @@ function Right({ userInput, updateField }) {
};
assets.push(thisAsset);
}
- tx.sendAssets(recipient.address, assets);
+ tx.sendAssets({ address: recipient.address }, assets);
}
}
diff --git a/packages/demo/components/pages/apis/transaction/setTimeLimit.tsx b/packages/demo/components/pages/apis/transaction/setTimeLimit.tsx
new file mode 100644
index 000000000..8253ef275
--- /dev/null
+++ b/packages/demo/components/pages/apis/transaction/setTimeLimit.tsx
@@ -0,0 +1,71 @@
+import Codeblock from '../../../ui/codeblock';
+import SectionTwoCol from '../../../common/sectionTwoCol';
+
+export default function SetTimeLimit() {
+ return (
+
+ );
+}
+
+function Left() {
+ let code1 = `import { resolveSlotNo } from '@martifylabs/mesh';\n`;
+ code1 += `let minutes = 5; // add 5 minutes\n`;
+ code1 += `let nowDateTime = new Date();\n`;
+ code1 += `let dateTimeAdd5Min = new Date(nowDateTime.getTime() + minutes*60000);\n`;
+ code1 += `const slot = resolveSlotNo('mainnet', dateTimeAdd5Min.getTime());\n`;
+
+ let codeExpire = `const tx = new Transaction({ initiator: wallet });\n`;
+ codeExpire += `// do tx.sendLovelace() or any transactions actions\n`;
+ codeExpire += `tx.setTimeToExpire(slot)\n`;
+ codeExpire += `const unsignedTx = await tx.build();\n`;
+
+ let codeValid = `const tx = new Transaction({ initiator: wallet });\n`;
+ codeValid += `// do tx.sendLovelace() or any transactions actions\n`;
+ codeValid += `tx.setTimeToStart(slot)\n`;
+ codeValid += `const unsignedTx = await tx.build();\n`;
+
+ return (
+ <>
+
+ We can define the time-to-live (TTL) for the transaction. TTL is the
+ time limit for our transaction to be included in a blockchain, if it is
+ not in a blockchain by then the transaction will be cancelled. This time
+ limit is defined as slot.
+
+
+ In order to get the slot of the time you wish the
+ transaction would expire, you can use resolveSlotNo. For
+ example, if you would like the transaction to expire in 5 minutes, we
+ can get the slot by doing:
+
+
+
+ Then, we set the TTL with setTimeToExpire and providing the{' '}
+ slot, this means that if the transaction is submitted after
+ after slot will not be valid.
+
+
+
+ Likewise, we can set a "validity start interval" for the transaction,
+ where it is the time the transaction will be valid. We can define the
+ start time with setTimeToStart and providing the{' '}
+ slot:
+
+
+
+ Note that, if you are using a policy locking script, you must define{' '}
+ setTimeToExpire before the expiry; otherwise, you will
+ catch the ScriptWitnessNotValidatingUTXOW error.
+
+ >
+ );
+}
+
+function Right() {
+ return <>>;
+}
diff --git a/packages/demo/components/pages/apis/transaction/unlockAssets.tsx b/packages/demo/components/pages/apis/transaction/unlockAssets.tsx
index b4e9b4298..6dd7a6ddd 100644
--- a/packages/demo/components/pages/apis/transaction/unlockAssets.tsx
+++ b/packages/demo/components/pages/apis/transaction/unlockAssets.tsx
@@ -1,17 +1,18 @@
import { useEffect, useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
-import RunDemoButton from '../common/runDemoButton';
-import RunDemoResult from '../common/runDemoResult';
-import SectionTwoCol from '../common/sectionTwoCol';
+import RunDemoButton from '../../../common/runDemoButton';
+import RunDemoResult from '../../../common/runDemoResult';
+import SectionTwoCol from '../../../common/sectionTwoCol';
import useWallet from '../../../../contexts/wallet';
-import ConnectCipWallet from '../common/connectCipWallet';
+import ConnectCipWallet from '../../../common/connectCipWallet';
import Input from '../../../ui/input';
import {
Transaction,
BlockfrostProvider,
resolveDataHash,
} from '@martifylabs/mesh';
+import Link from 'next/link';
// always succeed
const script = '4e4d01000033222220051200120011';
@@ -45,9 +46,9 @@ function Left({ assetUnit, inputDatum }) {
let codeSnippetGetAssetUtxo = `import { Transaction, BlockfrostProvider, resolveDataHash } from '@martifylabs/mesh';\n\n`;
codeSnippetGetAssetUtxo += `async function _getAssetUtxo({ scriptAddress, asset, datum }) {\n`;
codeSnippetGetAssetUtxo += ` const blockfrostProvider = new BlockfrostProvider(\n`;
- codeSnippetGetAssetUtxo += ` 'BLOCKFROST_API_KEY_PREVIEW',\n`;
+ codeSnippetGetAssetUtxo += ` 'BLOCKFROST_API_KEY',\n`;
codeSnippetGetAssetUtxo += ` );\n`;
- codeSnippetGetAssetUtxo += ` const utxos = await blockfrostProvider.fetchAddressUtxos(\n`;
+ codeSnippetGetAssetUtxo += ` const utxos = await blockfrostProvider.fetchAddressUTxOs(\n`;
codeSnippetGetAssetUtxo += ` scriptAddress,\n`;
codeSnippetGetAssetUtxo += ` asset\n`;
codeSnippetGetAssetUtxo += ` );\n`;
@@ -59,7 +60,15 @@ function Left({ assetUnit, inputDatum }) {
codeSnippetGetAssetUtxo += `}\n`;
let codeSnippetCreateTx = `const tx = new Transaction({ initiator: wallet })\n`;
- codeSnippetCreateTx += ` .redeemValue('${script}', assetUtxo, { datum: '${inputDatum}' })\n`;
+ codeSnippetCreateTx += ` .redeemValue({\n`;
+ codeSnippetCreateTx += ` value: assetUtxo,\n`;
+ codeSnippetCreateTx += ` script: {\n`;
+ codeSnippetCreateTx += ` version: 'V1',\n`;
+ codeSnippetCreateTx += ` code: '${script}',\n`;
+ codeSnippetCreateTx += ` },\n`;
+ codeSnippetCreateTx += ` datum: '${inputDatum}',\n`;
+ codeSnippetCreateTx += ` })\n`;
+
codeSnippetCreateTx += ` .sendValue(address, assetUtxo)\n`;
codeSnippetCreateTx += ` .setRequiredSigners([address]);\n`;
@@ -102,9 +111,9 @@ function Left({ assetUnit, inputDatum }) {
First, let's create a function to fetch input UTXO from the script
address. This input UTXO is needed for transaction builder. In this
demo, we are using BlockfrostProvider, but this can be
- interchange with other providers that Mesh provides. (We would have used{' '}
- KoiosProvider here, but unfortunately Koios do not support{' '}
- preview network.)
+ interchange with other providers that Mesh provides. We could have used{' '}
+ KoiosProvider here, see{' '}
+ Providers.
Get started
@@ -71,12 +70,12 @@ function Features() {
- Always up to date (Vasil ready)
+ Always up to date
Mesh is developed closely to the network updates. By using Mesh,
your application will always be ready for the latest network
- changes.
+ changes, so you can focus on building your application.