Developers
Tutorials

Contract Calling and Execution

8min

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.

Web3.JS Example

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:



JS




Calling to Read

This is the simplest type of contract call. We see an example using the popular Metamask wallet below:

JS




Creating a transaction to alter state

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.



JS




Creating a transaction to send CMP tokens

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.

JS




Ether JS

Ether.JS is a another popular package that is used to connect to smart contracts on EVM compatible blockchains.

Calling to read

Let's look at an example of a contract read action, using metamask.

JS




Creating a transaction to alter state:

Suppose a Solidity function is named buy. We would call it as follows through Javascript:

JS