Swisstronik & Ethereum calls

Calls in the blockchain context are read-only interactions with the blockchain, retrieving information from the blockchain without altering, deleting, or adding data.

Ethereum Calls

We can use ethers.js to execute calls to the Ethereum blockchain. specifically for smart contracts, we can use provider.call({to, data}) to retrieve values from smart contracts

provider.call({
  to: "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41",
  // Function selector for `function getMessage(uint256)` + encoded argument `1`
  data: "0xa5f3c4f600000000000000000000000000000000000000000000000000000000000000001"
});

In this code example, the function call is made to the to smart contract address, executing the view returns function getMessage(uint256) while providing the argument 1. This process will return a message from the smart contract.

Swisstronik Calls

For Swisstronik calls, we need to make sure the data field of the call is encrypted using SwisstronikJS.

provider.call({
  to: "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41",
  //The `data` field must be an encrypted value, otherwise, the call will not work
  data: "0xf53a7d4fcf3116b8476ac3f986542794f0df2516070c555580ae29049c0ec91b8a2d82d2bf06694fea0c485fa48cb34b596a9f496a19f2ecb3c1da0540544cffb03f1dee14d7887fea1de6d982a46edfaab773"
});

This example shows that when making Swisstronik calls, the data field needs to be filled with an encrypted value using SwisstronikJS. Otherwise, the call won't work. Let's now explore how to encrypt this data for successful calls on the Swisstronik blockchain.

Last updated