Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

readme.md

Swap

Swap contract facilitates the exchange of assets between two parties. This contract is designed to be used in a peer-to-peer exchange scenario where two parties agree to exchange assets. The contract ensures that the assets are locked up until it is accepted by the other party. At any point before it is accepted, one can cancel the swap to retrieve the assets.

There are 2 actions (or endpoints) available to interact with this smart contract:

  • initiate swap
  • accept asset
  • cancel swap

Read more and live demo

Usage

To initialize the swap, we need to initialize a provider, MeshTxBuilder and MeshSwapContract.

import { MeshSwapContract } from "@meshsdk/contracts";
import { BlockfrostProvider, MeshTxBuilder } from "@meshsdk/core";
import { useWallet } from "@meshsdk/react";

const { connected, wallet } = useWallet();

const provider = new BlockfrostProvider(APIKEY);

const meshTxBuilder = new MeshTxBuilder({
  fetcher: provider,
  submitter: provider,
});

const contract = new MeshSwapContract({
  mesh: meshTxBuilder,
  fetcher: provider,
  wallet: wallet,
  networkId: 0,
});