Contract Calling and Execution
Caduceus smart contracts are implemented on the Caduceus EVM. Therefore, it is easy to use widely available libraries such as Web3.js and Ether.js to call deployed contracts.
We will look at three possibilities when calling or executing.
First you must include Web3.js in your Javascript code. You can include it from a CDN such as Cloudflare as in the following example:
This is the simplest type of contract call. We see an example using the popular Metamask wallet below:
This is equivalent to writing to the Caduceus blockchain. A smart contract's methods may accept parametes such as integers, strings and booleans. These valuse will be persisted to the blockchain state upon a successful write.
Creating a transaction to send CMP involves first converting the amount to Wei, and then converting the Wei to a Hex value.
The ethereum.request object is available when Metamask is active for the user.
In this example, we have an error catcher within the function.
Ether.JS is a another popular package that is used to connect to smart contracts on EVM compatible blockchains.
Let's look at an example of a contract read action, using metamask.
Suppose a Solidity function is named buy. We would call it as follows through Javascript: