Function Parameters

We will give multiple examples here of how you are supposed to pass the function parameters for different parameter types. It will help you figure out how you should format the data you have to provide when calling the smart contract function. The formatting is quite easy and straightforward and as a matter of fact, the first idea that comes up to your mind is probably the correct choice (other than maybe more complex scenarios when encoding structs).

Example 1: Primitive types as parameters

πŸ‘‰πŸ» Example function signatures:

// Solidity Contract signatures
function myFunctionWithNoParameters() external view returns (uint256) {}
function myFunctionWithOneParameter(uint256 x) view returns (uint256) {}
function myFunctionWithTwoParameters(uint256 x, string memory y) view returns (uint256) {}

⚑️ How you call the functions using the SDK:

const contractInstance; // fetched from sdk (explained in section before)

const function1Result = await contractInstance.read(
    'myFunctionWithNoParameters',    // solidity function name
    [ ]                              // empty array because because function accepts 0 parameters
);
const function2Result = await contractInstance.read(
    'myFunctionWithOneParameter',    // solidity function name
    [ 123 ]                              // one number passed as parameter
);
const function3Result = await contractInstance.read(
    'myFunctionWithOneParameter',    // solidity function name
    [ 123, 'test string' ]           // one number and one string passed as parameters
);

Example 2: Arrays as parameters

πŸ‘‰πŸ» Example function signature:

⚑️ How you call the functions using the SDK:

Example 3: Structs as parameters

πŸ‘‰πŸ» Example function signature:

⚑️ How you call the functions using the SDK:

Example 4: Arrays of structs as parameters

Now let's say the function from example above accepts not one but an array of elements of type DataPoint.

πŸ‘‰πŸ» Example function signature:

⚑️ How you call the functions using the SDK:

Last updated