MultiBaas provides users with the ability to, on a per-method per-input/output parameter basis, adjust how the value is interpreted on its way to the blockchain, or adjust the return value on its way back from the blockchain.
One example would be to dynamically insert a decimal point into a smart contract method that returns an amount of type uint256. As exact decimal numbers are not supported by Solidity, the standard way of handling this situation is to use an integer and shift it by a fixed number of decimal places.
In the popular ERC20 token standard, a decimals() method provides the number of decimals place to shift the uint256 (unsigned integer) values for other methods input/output parameters that relate to token balances. For example, if decimals() returns 3, then the return value of the totalSupply() method should be shifted by 3 decimal places to the left.
We start by querying the totalSupply() method for the “autotoken” instance (an alias for the address of a smart contract deployed on the Ethereum blockchain).
The total supply is therefore 123,000. If we query the contract’s decimals() method:
Therefore, the result of totalSupply(), along with all other balance/amount method input/output parameters should be shifted by 3 decimal places to the left.
We could instruct MultiBaas to automatically shift the result of the totalSupply() function by 3 places:
We can also instruct MultiBaas to use the output of another function to specify the number of decimals. In this way we can support a varying number of decimals across smart contract instances with a single configuration setup of MultiBaas.
This decimals function must satisfy the following requirements:
Making another request to MultiBaas to use the output of decimals() for the number of decimals of the totalSupply() method:
Again calling the totalSupply() method:
The total supply is therefore 123.000, with the decimal place shifted three places to the left.
Type conversions can be previewed by running their inputs or outputs through a temporary, non-persisted type conversion. This is done to generate a preview of what the converted type will look like for presentation in a UI.
The API request and response to preview a type conversion is as follows.
From the UI you can also update the type conversion settings.
MultiBaas comes with a number of sample smart contracts pre-installed. They may be linked to deployed contracts on the blockchain or just...
Multisignature (multisig) wallets are smart contracts that allow multiple signers to review and agree on an action on the blockchain ...