In the second part of this series, we will delve into the endpoints of the Marketplace contract. This contract is part of a suite of Aiken smart contracts built to redefine reusability and developer engagement, setting a new standard in the field.
Contract: Marketplace (try it: link to the main tweet)
Today: Contract Endpoints (List Asset, Buy Asset, Update Listing, Cancel Listing)
Endpoint: List Asset
What does it make possible to list assets in the Marketplace for sale?: The listAsset()
function.
The function accepts the following parameters:
asset (string) - the asset’s unit to be listed price (number) - the listing price in Lovelace
const tx = await contract.listAsset('d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e', 10000000);
const signedTx = await wallet.signTx(tx);
const txHash = await wallet.submitTx(signedTx);
Endpoint: Buy Asset
What does it make possible to purchase a listed asset from the marketplace?: The purchaseAsset()
function.
The function accepts the following parameters:
utxo (UTxO) - unspent transaction output in the script
const utxo = await contract.getUtxoByTxHash(txHashToSearchFor);
const tx = await contract.purchaseAsset(utxo);
const signedTx = await wallet.signTx(tx, true);
const txHash = await wallet.submitTx(signedTx);
Endpoint: Update Listing
What allows a seller to update the price of its merchandise in the marketplace?: The relistAsset()
function
The function accepts the following parameters:
utxo (UTxO) - unspent transaction output in the script newListPrice (number) - the new listing price in Lovelace
const utxo = await contract.getUtxoByTxHash(txHashToSearchFor);
const tx = await contract.relistAsset(utxo, 20000000);
const signedTx = await wallet.signTx(tx, true);
const txHash = await wallet.submitTx(signedTx);
Endpoint: Cancel Listing
What allows sellers to cancel their listing at any time and receive their product back?: The delistAsset()
function.
The function accepts the following parameters:
utxo (UTxO) - unspent transaction output in the script
const utxo = await contract.getUtxoByTxHash(txHashToSearchFor);
const tx = await contract.delistAsset(utxo);
const signedTx = await wallet.signTx(tx, true);
const txHash = await wallet.submitTx(signedTx);
Would you like to test drive this code? Go to Marketplace Contract - MeshJS
Mesh: making life easier for developers
In part 3: a new contract - the Vesting contract.