cargo.api

cargo.api exposes methods that can be called without an Ethereum enabled browser (provider) along with methods that require an Ethereum enabled browser. Methods that require a provider can be called after calling cargo.enable . Some methods will require authentication. An authentication token is provided after calling the register, or authenticate methods - both of which require an Ethereum enabled browser.

How things are documented

Each method will be described in English and then an example call of the method will be documented. Arguments are described using English while return types are described using TypeScript types. Arguments are required unless they are specified as optional.

Emoji Legend

🌎 - Open method, authentication not required

🦊 - Method requiring MetaMask, or similar Web3 browser or extension. These methods use Web3 API's.

πŸ”’ - Authenticated method, authentication required. A pre-requisite to authentication is getting an access token and to get an access token requires MetaMask or something like it. So by default all authenticated methods are also 🦊.

πŸ• - Optional authenticated method. Authentication is optional and may affect response.

​

🌎 Get a list of collectibles

You can use this method to get a paginated list of collectibles for any collection that adheres to the ERC-721 specification and includes the enumeration extension.

cargo.api.getTokensByContract(options).then(response => {
// Do something with response
});
Arguments
Response
Arguments

Argument

Description

options

An object containing the following properties:

  • contractAddress - Required. Address of the contract you wish to query

  • page - Optional. Optional page for pagination.

  • limit - Optional. Limit the number of results returned. Defaults to 10.

Response
type Response = {
err: boolean,
status: number,
data: {
// Contract name
name: string,
// Contract symbol
symbol: string,
// Array of tokens
results: {
tokenId: string,
metadata: Object,
tokenURI: string,
}[],
// Total number of tokens in contract
totalSupply: string,
// Current page
page: string,
// Limit
limit: string,
// Total number of pages
totalPages: string,
}
}

πŸŒŽπŸ• Get Cargo collection metadata

You can use this method to get information about a collection. A requirement is that the specified collection (ERC-721 contract address) must exist in the Cargo system. This contract doesn't necessarily need to be created on Cargo, but it needs to have been indexed by Cargo. Contracts are indexed when you register with your Ethereum address. If an auth token is present then an additional isOwned value will be returned in the response.

cargo.api.getContractMetadata(collectionAddress).then(response => {
// Do something with response
});
Arguments
Response
Arguments

Argument

Description

collectionAddress

Cargo ERC-721 contract address

useAuth

Optional. Boolean. If true then the user must be authenticated and the user's auth token will be sent in the request. An addition isOwned property will be in the response body.

Response
type Response = {
err: boolean;
status: number;
data: {
// Total number of collectibles in collection
totalSupply: string;
// Collection address
address: string;
// Collection name
name?: string;
// Collection symbol
symbol?: string;
// Cargo ID representing owner of collection
owner?: string;
// Timestamp of creation
createdAt: string;
// Boolean stating if the current user created the contract
isOwned?: boolean;
}
}

🌎 Get collectible details

You can use this method the get details for a given collectible.

cargo.api.getTokenDetails(collectionAddress, collectibleId).then(response => {
// Do something with response
});
Arguments
Response
Arguments

Argument

Description

collectionAddress

The address of the collection.

collectibleId

The ID of the collectible within the collection.

Response
type Response = {
err: boolean,
status: number,
data: {
// Username of owner
owner?: string,
// Address of owner
ownerAddress: string,
// If this item is for sale, details about sale
resaleItem?: {
seller: string,
contract: string,
tokenId: string,
price: string,
signatureGenerator?: boolean,
groupId: string
crate: string,
createdAt: string,
},
// Collectible ID
tokenId: string,
// Name of collection token belongs to
contractName: string,
// Symbol of collection token belongs to
contractSymbol: string,
}
}

πŸŒŽπŸ• Get a list of collectibles that are for sale

You can use this method to get a paginated list of collectibles that are for sale. You can filter collectibles in the response. See arguments for details.

cargo.api.getResaleItems(options).then(response => {
// Do something with response
});
Arguments
Response
Arguments

Argument

Description

options

An object that contains the following properties:

  • showcaseId - Optional. String. Display resale items by a given showcase.

  • collectionId - Optional. String. Display resale items for a given collection.

  • page - Optional. String. Page in results to display.

  • limit - Optional. String. Limit of results per page.

  • owned - Optional. Boolean. Display resale items that are owned by the current authenticated user only.

Response
type SuccessResponse = {
err: false,
status: 200,
data: {
limit: string,
page: string,
totalPages: string,
results: {
seller: string,
// ID of the collection
contract: string,
// Id of the collectible
tokenId: string,
// Price in Wei that the collectible is selling for
price: string,
// If owned is true this will show the user if purchase signatures
// have been generated. If they have cancelling the sale safely will
// require a transaction to be submitted.
signatureGenerated?: boolean,
// Will only be in response if owned is set to true. This can be
// used to safely cancel a sale. You can use the cancelSale method
// and Cargo JS will handle this for you.
groupId?: string,
// Showcase ID resale item belongs to
crate?: string,
createdAt: string,
}[]
}
}

πŸŒŽπŸ• Get a list of collections on Cargo

You can use this method to get a paginated list of collections (ERC-721 contracts). You can filter contracts in the response. See arguments for details.

cargo.api.getContracts(options).then(response => {
// Do something with response
});
Arguments
Response
Arguments

Argument

Description

options

An object containing the following properties:

  • page - Optional. String. Page of results to display. Defaults to 1.

  • limit - Optional. String. Limit of collections per page. Defaults to 10.

  • showcaseId - Optional. String. Limit results to show only collections in the given showcase.

  • owned - Optional. Boolean. Show only collections that the current authenticated user owns.

  • useAuthToken - Optional. Boolean. Show only collections that the current authenticated user either owns, or has collectibles in. Collections within response will contain an additional contractTokens property stating how many collectibles the user owns within that collection. This takes precedence over the owned parameter.

Response
type Response = {
err: boolean,
status: number,
data: {
results: {
// ID of collection
_id: string,
address: string,
name: string,
symbol: string,
supportsMetadata: boolean,
createdAt: string,
// total number of owned collectibles in collection
// Available only when useAuthToken === true
totalOwned?: number,
// Available only when useAuthToken === true
owned?: boolean,
}[],
limit: string,
totalPages: string,
total: string,
page: string,
}
}

πŸŒŽπŸ• Get a showcase by ID

You can use this method to get information about a showcase by it's ID. If the showcase is private you will need to be authenticated and be either the owner or the vendor of that showcase.

cargo.api.getShowcaseById(showcaseId, auth).then(res => {
// do something with response
});
Arguments
Response
Arguments

Argument

Description

showcaseId

Required. String. The ID of the showcase

auth

Optional. Boolean. If true you must be authenticated and your authentication token will be sent in with the request. This will be required to get information about a private showcase.

Response
type SuccessResponse = {
err: false,
status: 200,
data: {
name: string;
createdAt: string;
public: boolean;
isOwner?: boolean;
isVendor?: boolean;
}
}

πŸŒŽπŸ• Get information about a collection

You can use this method to get information about a given collection by it's address such as the name, symbol and total number of collectibles within that collection. If you pass an auth token Cargo will tell you if the account tied to the given token is the creator of that collection. You can also pass a showcase slug and slug ID to check if the collection is contained within that showcase.

cargo.api.getContractMetadata(contractAddress, useAuth, slug, slugId)
.then(response => {
// Use response
});
Arguments
Response
Arguments

Argument

Description

contractAddress

Required. The address of the collection to get information for.

useAuth

Optional. If true this method requires authentication. Will return isOwned boolean in response.

slug

Optional. Showcase slug to check if collection is contained within showcase.

slugId

Optional. Slug ID associated with passed in slug argument.

Response
type SuccessResponse = {
err: false;
status: 200;
data: {
totalSupply: number;
address: string;
name: string;
cargoContract: boolean;
symbol: string;
supportsMetadata: boolean;
createdAt: string;
}
}

πŸ”’ Bulk metadata update

You can use this method to update the metadata for many collectibles in a collection at one time. Existing metadata for specified collectibles will be replaced.

// Updates are made using an object where the keys represent the
// token ID to be updated and the value is a JSON serializable object
// which is the update.
​
// For example:
const updates = {
// 1 is the ID of the collectible and the value
// is the new metadata
1: {
name: 'Crypto hero',
description: 'Something about this collectible',
},
2: {
name: 'Crypto Goblin',
description: 'Something about this collectible',
},
}
​
cargo.api.bulkMetadataUpdate(collectionAddress, updates).then(response => {
if(response.status === 200) {
// success
}
});
Arguments
Response
Arguments

Argument

Description

collectionAddress

The collection in which to update collectible metadata

updates

An object where keys represent the collectible ID and the value is a JSON serializable object containing the new metadata

Response
type SuccessResponse = {
status: 200,
err: false,
data: {
code: 'success',
}
}

πŸ”’ Add a collection to a showcase

You can use this method to add a collection to a showcase.

cargo.api.addCollectionToShowcase(collectionId, showcaseId).then(response => {
if(response.status === 200) {
// Success
}
});
Arguments
Response
Arguments

Argument

Description

collectionId

The ID of the collection you want to add to the given showcase.

showcaseId

The ID of the showcase you want to add the collection to.

Response
type SuccessResponse = {
err: false,
status: 200,
data: {
code: 'success',
}
}

πŸ”’ Get collectibles for a user by collection

You can use this to get the owned collectibles for a user in a given collection. The contractId is not the address of the collection, but the ID which can be retrieved using the getContracts method.

cargo.api.getUserTokensByContract(options).then(response => {
// Do something with response
});
Arguments
Response
Arguments

Argument

Description

options

An object that has the following properties:

  • page - Optional. String. Page of results to display.

  • limit - Optional. String. Limit of results to display per page.

  • contractId - Required. String. ID of collection

Response
type SuccessResponse = {
err: false,
status: 200,
data: {
results: {
tokenId: string,
metadata: {},
tokenURI: string,
}[],
limit: string,
totalPages: string,
page: string,
total: string
}
}

πŸ”’ Get showcases for a user

You can use this method to get a paginated list of the showcases the authenticated user has created.

cargo.api.getUserShowcases(options).then(response => {
// Do something with response
});
Arguments
Response
Arguments

Argument

Description

options

An optional object with the following properties:

  • page - String. Optional. Page number of results to return.

  • limit - String. Optional. Limit of results to display on each page.

Response
type Response = {
err: boolean,
status: number,
data: {
results: {
name: string,
id: string,
}[],
// Total number of showcases created
total: string,
// Current page
page: string,
// Limit
limit: string,
// Total number of pages
totalPages: string,
}
}

πŸ”’ Get vendors in a showcase

You can use this method to get a paginated list of vendors for a given showcase. The authenticated user must be the owner of the showcase.

cargo.api.getShowcaseVendors(showcaseId).then(response => {
// Do something with response
});
Arguments
Response
Arguments

Argument

Description

showcaseId

ID of showcase to return vendors for.

Response
type Response = {
err: boolean,
status: number,
data: {
results: {
// Address of vendor
address: string
// Cargo id of vendor
_id: string,
// Username of vendor
displayUsername: string,
}[],
// Total number of showcases created
total: string,
// Current page
page: string,
// Limit
limit: string,
// Total number of pages
totalPages: string,
}
}

πŸ”’ Get beneficiaries for a vendor

You can use this method to get a paginated list of beneficiaries for the given vendor. Vendors are in relation to a showcase so a showcase ID is also required.

cargo.api.getVendorBeneficiaries(vendorAddress, showcaseId).then(results => {
// Do something with results
});
Arguments
Response
Arguments

Argument

Description

vendorAddress

The address of the vendor

showcaseId

The showcase the vendor belongs to for which you'd like to retrieve beneficiaries for.

Response
type Response = {
err: boolean,
status: number,
data: {
results: {
// The address of the beneficiary
address: string,
// The commission of the beneficiary
commission: string,
// The address of the vendor for whom this
// beneficiary belongs to
vendorAddress: string,
// The showcase ID
crateId: string,
// Timestamp for when the vendor was created
createdAt: string,
}[],
// Total number of showcases created
total: string,
// Current page
page: string,
// Limit
limit: string,
// Total number of pages
totalPages: string,
}
}

🦊 Create an account

You can use this method to create a new Cargo account. The response will contain an JSON web token that is used to make authenticated requests. Cargo JS stores this token for you so you don't need to worry about storing it. When creating an account the user will be asked to sign a message to prove they are who they say they are.

cargo.api.register(email, username).then(response => {
if(response.status === 200) {
// User has been created and is authenticated
// for future requests
}
});
Arguments
Response
Arguments

Argument

Description

email

Valid email address that will be tied to the account

username

Username to be used for new account

Response
type Response = {
err: boolean,
status: number,
data: {
// JSON web token
token: string,
}
}

🦊 Authenticate existing account

You can use this method to authenticate and existing account. The response will contain an JSON web token that is used to make authenticated requests. Cargo JS stores this token for you so you don't need to worry about storing it. When authenticating an account the user will be asked to sign a message to prove they are who they say they are.

cargo.api.authenticate().then((response) => {
if(response.status === 200){
// User is authenticated
}
});
Arguments
Response
Arguments

This method does not take any arguments.

Response
type SuccessResponse = {
err: false,
status: 200,
data: {
// JSON web token
token: string
}
}
​
​
// If an account is required you will get this response
type AccountRequiredResponse = {
err: true,
status: 401,
data: {
code: 'account-required'
}
}

🦊 Get Cargo credit balance

Use this method to get the Cargo credit balance of the current user. Cargo credits are required to create collectibles.

cargo.api.getMintingCreditBalance().then(balance => {
// Do something with balance
});
Arguments
Description
Arguments

This method doesn't take any arguments.

Description

This method returns the balance of Cargo credits for the current user.

🦊 Purchase a collectible

You can use this method to purchase a collectible. You do not need to have registered an account on Cargo to use this method. You will just need a Web3 enabled browser.

cargo.api.purchase(collectibleId, collectionAddress).then(txHash => {
// Transaction submitted
});
Arguments
Response
Arguments

Argument

Description

collectibleId

The ID of the collectible to purchase

collectionAddress

The address of the collection (ERC-721 contract) that contains the collectible.

Response

The response will contain a transaction hash.

🦊 Transfer a collectible

You can use this method to transfer a collectible you own to another address.

cargo.api.transferCollectible(contractAddress, tokenId, toAddress).then(txHash => {
// Transaction submitted
});
Arguments
Second Tab
Arguments

Argument

Description

contractAddress

The collection address for which the collectible belongs to.

tokenId

The ID of the collectible to transfer.

toAddress

The Ethereum address to transfer the collectible to.

Second Tab

The response will contain a transaction hash.

πŸ¦ŠπŸ• Set a collectible for sale

Owners of a collectible can sell a collectible through Cargo by using this method. Cargo must be approved to transfer the collectible on your behalf. This method will verify that Cargo is approved to transfer your collectible. If Cargo is not approved the setApprovalForAll method will be called before marking the item for sale. Cargo

cargo.api.sell(options).then(response => {
if(!response.err){
// Item has been marked for sale
}
});
Arguments
Response
Arguments

Argument

Description

options

An object with the following properties:

  • contractAddress - Required. The address of the collection containing the collectible to sell.

  • tokenId - Required. The ID of the collectible.

  • price - Required. The price, in Wei, of the collectible.

  • crateId - Optional. The showcase ID representing the showcase in which this item will be displayed for sale in.

Response
type Response = {
err: boolean,
status: number,
data: {
// ID of newly created resale item
resaleItemId: string,
}
}

πŸ¦ŠπŸ• Cancel a sale

You can cancel a sale by using this method. You must either have authenticated with the same address used to initiate the sale of the item, or you must be able to sign a message with that address. For security purposes, if a signature has been generated for the purchase of this collectible you will be required to execute a transaction to Cargo's smart contract to ensure the collectible cannot be sold. This method will automatically call the smart contract method if it is required.

cargo.api.cancelSale(resaleItemId).then(response => {
// Response will contain either a transaction hash
// or a typical Cargo response.
});
Arguments
Response
Arguments

Argument

Description

resaleItemId

The ID of the resale item.

Response

If signatures have been generated to purchase this item then a transaction will be required. The response will contain a transaction hash. If no transaction is required then signatures have not been generated. response will have the following shape if no signatures were generated:

type Response = {
status: 200,
err: false,
data: {
signatureGenerated: false,
code: 'success',
}
}

πŸ¦ŠπŸ”’ Create a showcase

You can use this method to create a new showcase.

cargo.api.createShowcase(showcaseName).then(response => {
if(response.status === 200) {
// Showcase created
}
});
First Tab
Response
First Tab

Argument

​

showcaseName

The name of your new showcase

Response
type Response = {
err: false,
status: 200,
data: {
showcaseId: string
}
}

πŸ¦ŠπŸ”’ Set application fee for a showcase

You can use this method to set an application fee for a showcase. An application fee is the percentage of funds the showcase owner will receive upon the selling of a vendor collectibles in that showcase. The fee can be from 0 to 0.2 meaning the maximum percentage a showcase owner can receive is 20% of each sale.

cargo.api.setShowcaseApplicationFee(fee, showcaseId).then(txHash => {
// Tx submitted
});
Arguments
Response
Arguments

Argument

Description

fee

A number from 0 to 0.2 representing the fee as a percentage

showcaseId

ID of the showcase to add the fee to.

Response

The response will contain a transaction hash.

πŸ¦ŠπŸ”’Remove a vendor

An owner of a showcase can use this method to remove a vendor from within that showcase.

cargo.api.removeVendor(vendorAddress, showcaseId).then(txHash => {
// Transaction has been submitted. cargo.pollTx will emit an event
// when the transaction has been confirmed.
});
Arguments
Response
Arguments

Argument

Description

vendorAddress

Address of the vendor to remove

showcaseId

ID of the showcase to remove the vendor from

Response

The response will contain a transaction hash.

πŸ¦ŠπŸ”’Create a new collection (ERC-721 contract)

You can use this method to create a new collection (ERC-721 contract) on the Ethereum blockchain. This method will require the user submitting the transaction to pay the required fees for deploying a new collection. You can pass in an optional Showcase ID to automatically add the collection to that Showcase after it's been created. The cost will be 0.1 ETH (the standard cost to create a Cargo ERC-721 contract).

cargo.api.createContract(name, symbol, showcaseId).then(txHash => {
// Transaction has been submitted
});
Arguments
Response
Arguments

Argument

Description

name

Name of your collection

symbol

Ticker symbol of your collection

showcaseId

Optional. Showcase ID in which the collection will be added to after creation.

Response

The response will contain a transaction hash.

πŸ¦ŠπŸ”’Create new collectibles

Use this method to create new collectibles. You can use this method to create one or many collectibles depending on the amount of Cargo credits you have. When creating many collectibles they will all initially share the same name, description, preview image, metadata, and associated files. Cargo will add an "edition" field to the JSON metadata file associated with the collectible which corresponds to the consecutive collectible ID. If you need to update these fields for individual collectibles you can use the Bulk Metadata Update method to accomplish this.

cargo.api.mint(options).then(txHash => {
// Transaction submitted
});
Arguments
Response
Arguments

Argument

Description

options

Options is an object with the following fields:

  • contractAddress - The address of the contract to create collectibles in.

  • amount - The number of collectibles to create

  • to - The address in which to send the collectible(s)

  • name - Optional. Name of collectible(s)

  • description - Optional. Description of collectible(s)

  • metadata - Optional. JSON serializable object containing arbitrary metadata for your collectible(s)

  • previewImage - Optional. A File.

  • files - Optional. An array of Files that only the owner of the collectible will have access to.

Response

The response will contain a transaction hash.

πŸ¦ŠπŸ”’Add a vendor

In order for any user to sell items in a showcase they must be added as a vendor to that showcase (including the owner of the showcase). Use this method to add vendors to a showcase.

cargo.api.addVendor(vendorAddress, showcaseId).then(txHash => {
// Transaction submitted
});
First Tab
Second Tab
First Tab

Argument

Description

vendorAddress

The address of the vendor to add to the showcase

showcaseId

The ID of the showcase

Second Tab

The response will contain a transaction hash.

πŸ¦ŠπŸ”’Add a beneficiary

A vendor can use this method to add a beneficiary.

cargo.api.addBeneficiary(showcaseId, beneficiaryAddress, commission)
.then(txHash => {
// transaction submitted
})
.catch(e => {
// something went wrong
});
Arguments
Response
Arguments

Argument

Description

showcaseId

ID of the showcase that the user submitting the transaction is a vendor in. The beneficiary will be added to that vendor within that showcase.

beneficiaryAddress

The address of the beneficiary you'd like to add

commission

A number between 0 and 1 representing the percentage of each sale this beneficiary will receive.

Response

The response will contain a transaction hash.

πŸ¦ŠπŸ”’Remove a beneficiary

Vendors can use this method to remove a beneficiary. The sending address must represent the vendor and the beneficiary address passed to the method must be owned by the vendor. The showcase ID must represent the showcase in which the beneficiary and vendor reside.

cargo.api.removeBeneficiary(beneficiaryAddress, showcaseId).then((txHash) => {
// Transaction submitted
});
Arguments
Response
Arguments

Argument

Description

beneficiaryAddress

The beneficiaries address

showcaseId

The ID of the showcase containing the beneficiary

Response

The response will contain a transaction hash.

πŸ¦ŠπŸ”’Update the commission of a beneficiary

Use this method to update the commission of an existing beneficiary.

cargo.api.updateBeneficiaryCommission(beneficiaryAddress, commission, showcaseId)
.then(txHash => {
// Transaction submitted
});
Arguments
Response
Arguments

Argument

Description

beneficiaryAddress

The address of the beneficiary to update the commission for.

commission

A number between 0 and 1 representing the percentage of each sale this beneficiary will receive.

showcaseId

The ID of the showcase the vendor and beneficiary belongs to.

Response

The response will contain a transaction hash.