cargo

cargo

init()

Use cargo.init() to initialize Cargo.

Arguments:

This method does not take any arguments.

Returns:

This method returns a Promise.

Events:

has-metamask-but-not-enabled - Emitted when the user has MetaMask, but it still needs to be enabled.

metamask-required - Emitted when MetaMask is not available in the user's browser.

Example:

cargo.init().then(() => {
// Cargo is ready to use. Call cargo.enable to connect to metamask
});

enable()

Use the enable method after you have called init to connect to MetaMask and get access to the current account. This method requires Cargo to be successfully initialized by calling init . After calling enable you can use API methods that require MetaMask.

Arguments:

This method doesn't take any arguments.

Returns:

This function returns a Promise and resolves with a boolean stating whether a successful connection to MetaMask has been made.

Events:

enabled - Emitted when successfully enabled.

has-metamask-but-not-enabled - Emitted if the user has MetaMask, but declined to connect to Cargo.

metamask-required - Emitted if the user does not have MetaMask.

on(event, listener)

Use the on method to add event listeners.

Arguments:

This method takes two arguments:

Parameter

Description

event - CargoEvent

The event to listen for.

listener - function

The listener is a function that takes data as an argument.

off(event, listener)

Use the off method to remove an event listener.

Arguments:

This method takes two arguments:

Parameter

Description

event - string

The event to listen for.

listener - function

The listener is a function that takes data as an argument.

removeAllListeners(event)

Use the removeAllListeners method to remove all listeners for a given event.

Arguments:

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

getCommission(percentage)

Use the getCommission method to calculate beneficiary commissions. When updating beneficiary commissions, or application fees the total amount of all commissions cannot equal more than 100%.

Arguments:

This method takes one argument, percentage which is a number between 0 and 1.

Example:

// Calculate a 2% commission
const commission = cargo.getCommission(0.02);
console.log(commission); // '20000000000000000'

createCargoTokenV1Instance(address)

Use this method to create an instance of a Cargo Token V1 contract at a specified address.

Arguments:

This method takes one argument, a string, which is the address of the contract you wish to interact with.

Returns

An initialized contract using web3 v0.27.0

createCargoTokenV2Instance(address)

Use this method to create an instance of a Cargo Token V2 contract at a specified address.

Arguments:

This method takes one argument, a string, which is the address of the contract you wish to interact with.

Returns

An initialized contract using web3 v0.27.0

Cargo Events

The following events can be passed to the on function

accounts-changed

has-metamask-but-not-enabled

enabled

metamask-required