The operator is the entity mainly responsible for producing, delivering and installing the asset. The operator receives the crowdsale funds in exchange for producing the asset. In our case, the operator receives funds to deliver coffees to investors that signed up to our platform.
In this simple "hello world" example we are setting the operator to be the same entity as the broker. In reality, these roles can be played by different entities. See roles in the MyBit network SDK.
const to get a list of accounts controlled by the node. It uses the Web3 API to return an array of ethereum addresses.
const accounts = await web3.eth.getAccounts()
Assign the second address in the array to be the operatorAddress.
const [platformOwner, operatorAddress] = accounts
At this stage, we set an asynchronous
function setOperator(). It will check whether an operator is already set or not in the platform. First, check the operator is already set:
//Check if operator is already setvar operatorURI = 'Mac the Operator';var id = await api.generateOperatorID(operatorURI);var currentAddress = await api.getOperatorAddress(id);if (currentAddress == '0x0000000000000000000000000000000000000000')
If all set then:
console.log('Operator already set')
If the operator is not set, it will add a new operator to the platform, with an associated ID value, by parsing
//If not setid = await Network.addOperator(operatorAddress,operatorURI,platformOwner);
The application will also make sure the operator accepts to receive payments in ether.
await Network.acceptEther(id, operatorAddress);
Only then the application returns the set ID value for the operator in the platform.
Under the hood, setting up the operator involves interacting with
network.js and the APIs to interact with MyBit SDK contracts.