Provider Methods

These method will require that the user have MetaMask installed on their browser.

mint(parameters)

Use the mint method to mint a new token or batch of tokens if you have created a Cargo Token V2 contract that supports batch minting. This method requires MetaMask and will ask the user to first sign a message to verify they are the owner of the address that will be minting the token. Once the user signs the message this method will call the Cargo server with the required data and will return transaction data to execute the transaction.

Arguments:

This method takes one argument, an Object with the following fields

Key

Value

tokenAddress - string - required

The address of the token contract that will mint the token.

vendorId - string - required

The ID of the vendor calling this method. This vendor must be owned by the address making the transaction.

batchMint - boolean

Boolean stating whether or not you'd like to batch mint. Only valid for Cargo Token V2 contracts.

batchNumber - string

String number saying how many tokens you'd like to mint Only valid for Cargo Token V2 contracts and when batchMint is true.

hasFiles - boolean - required

Boolean stating whether or not files will be associated with this token. If true the files property must be set.

files - Array<File> - optional

An array of Files, required if hasFiles is true.

previewImage - File - optional

A File that will be a publicly available preview image for the token.

name - string - optional

The name of the token.

description - string - optional

Optional description of the token.

metadata - string - optional

JSON stringified object of metadata that will be added to the public metadata file.

to - string - optional

The address to send the token to after minting. If undefined it will default to the current connected address.

Returns:

This method returns a Promisethat resolves with a transaction hash once the transaction is submitted.

Example:

cargo.api.mint(params).then(txHash => {
// Do something
});

cancelTokenSale(resaleItemId)

Use the cancelTokenSale method to cancel the sale of the given resaleItemId. The address sending the transaction must be the owner of the resale item (the person selling the token).

Arguments:

This method has one argument a string which is the resaleItemId.

Returns:

This method returns a Promise that resolves with a transaction hash once the transaction is submitted.

download(contractAddress, tokenId)

Use this method to get download links for files tied to a token and the private metadata file. This method requires the caller to sign a message to prove they are the owner. The download links will expired after five minutes.

Arguments:

This method takes two arguments:

  • contractAddress - The contract address which the token belongs to.

  • tokenId - string - the token ID for which to retrieve the download links.

Returns:

This method returns a Promise which resolves an Object with the following properies:

response.err - boolean

response.data - Object

response.data.assetFileUrl - string - A signed URL that will allow the download of the asset files.

response.data.metadata - string - A signed URL that will allow the download of the private metadata file.

createBatchTokenContract(vendorId, contractName, symbol)

Use the createBatchTokenContract function to create a new ERC-721 token contract that supports batch minting.

Arguments:

This method takes three arguments and they are:

  • vendorId - string - Required - The ID of the vendor creating the contract. The account executing the transaction must be the owner of the vendor ID.

  • contractName - string - Required - The name of your contract

  • symbol - string - Required - Symbol of your contract. Can be an empty string.

Returns:

This method returns a Promise that resolved with a transaction hash on the transaction is submitted.

Example

const vendorId = '28';
const contractName = '👻';
const symbol = '👋';
cargo.api.createBatchTokenContract(vendorId, contractName, symbol)
.then(txHash => {
// Can watch for completion of transaction by
// using the cargo.pollTx instance
});

createTokenContract(parameters)

Use the createTokenContract method to create a new ERC-721 token contract. This method requires MetaMask.

Arguments:

This method takes an object with the following properties:

  • vendorId - string - The ID of the vendor who is creating the contract. The sender of the transaction must be the owner of the vendor.

  • tokenContractName - string - The name of the token contract.

  • symbol - string - The symbol of the token contract.

  • limitedSupply - boolean - States whether the contract will have a limited supply of tokens that can be minted.

  • maxSupply - string - If limited supply is set to true maxSupply is the number of tokens that can be minted within the contract.

Returns:

This method returns a Promise that resolves with a transaction hash once the transaction is submitted.

Example:

cargo.api.createTokenContract(
'2',
'Rare Items',
'🤗',
'false',
'0'
).then(tx => {
// Do something
});

createCrate(publicVendorCreation)

Use this method to create a new crate.

Arguments:

  • publicVendorCreation - boolean - If set to true any address can add themselves as a vendor to this crate. Defaults to false.

Returns

This method returns a Promise which resolves the transaction hash which is a string.

Example:

cargo.api.createCrate().then(tx => {
// Do something. Maybe poll tx until complete.
});

createCrateWithCallbackContract(publicVendorCreation, callbackContractAddress)

Use this function to create a crate with a specified contract address which will be called when certain events happen. The contract must adhere to the Cargo callback contract interface.

Arguments

  • publicVendorCreation - boolean - If set to true any address can add themselves as a vendor to this crate. Defaults to false.

  • callbackContractAddress - string - The address of your custom contract that adheres to the Cargo callback contract interface.

Returns

This method returns a Promise which resolves the transaction hash which is a string.

Learn more about Cargo callback contracts.

updateCrateApplicationFee(fee, crateId)

Use this method to update your crate's application fee. The fee should be calculated using the cargo.getCommission function. This fee will only apply to vendors added after the update.

Arguments

  • fee - New crate application fee

  • crateId - Crate to update

Returns

This method returns a Promise which resolves the transaction hash which is a string.

Example

cargo.api.updateCrateApplicationFee(cargo.getCommission(5)).then((tx) => {
//...
});

withdraw(amount, beneficiaryId, to)

Use this method to withdraw funds for a given beneficiary.

Arguments

  • amount - Amount in Wei to withdraw

  • beneficiaryId - The beneficiary wallet to withdraw from

  • to - The address to send the funds to

Returns

This method returns a Promise which resolves the transaction hash which is a string.

resellerWithdraw(to, amount)

Use this method to withdraw funds based on the sending address.

Arguments

  • to - Address to send funds to

  • amount - Amount to withdraw

Returns

This method returns a Promise which resolves the transaction hash which is a string.

purchaseResaleToken(resaleItemId, amount)

Use this method to purchase a resale item.

Arguments

  • resaleItemId - ID of resale item to purchase

  • amount - Price of resale token. Will be used to determine how much Wei will be sent with transaction.

getOwnedBeneficiaries()

Use this method to get a list of beneficiary IDs which correspond to the sending address.

getOwnedVendors()

Use this method to get a list of vendor IDs which correspond to the sending address.

getOwnedCrates()

Use this method to get a list of crate IDs for which the sending address owns.

sellOwnedToken(tokenAddress, tokenId, price, fromVendor)

Use this method to sell a give token.

Arguments:

This methods takes four arguments:

  • tokenAddress - string - Address of the token to sell

  • tokenId - string - ID of the token to sell

  • price - string - price of token in wei

  • fromVendor - boolean - Boolean stating if the sending address is the vendor that created the token. If set to true then the proceeds from the sale will be split between all the vendor's beneficiaries.

The following methods are deprecated and will not work with new contracts. DON'T USE THEM.

DEPRECATED - getOwnedTokenIdsByCargoTokenContractId(cargoTokenContractId)

Use the getOwnedTokenIdsByCargoTokenContractId method to get a list of token IDs that the given address owns in the given Cargo Token Contract. The wallet address to fetch tokens for is determined by the sender of the transaction.

Arguments

This method takes one argument, cargoTokenContractId, which is a string.

Returns:

This method will return a Promise that resolved a list of token IDs that the sender owns in a given contract.

Example:

cargo.api.getOwnedTokenIdsByCargoTokenContractId(contractId).then(ownedTokens => {
// Do something with list of owned tokens.
});

DEPRECATED - getOwnedCargoTokenContractIds()

Use the getOwnedCargoTokenContractIds to get a list of Cargo Token Contract IDs that the sender has a stake in. Meaning that the sender owns a token within the contract. This can be used to get all the owned tokens for a user.

Arguments

This method does not take any arguments, but uses the sender of the transaction to determine the address to fetch data for.

Returns:

This method returns a Promise that will resolve with a list of Cargo Token Contract IDs that the sender has a stake in.

Example:

cargo.api.getOwnedCargoTokenContractIds().then(tokenContractIds => {
// Do something
});