Ethereum: transfer of arguments to scripts
By writing intelligent reliability contracts, one of the most common challenges is to transfer arguments to the scripts. In this article, we will examine the method of transferring arguments to reliability scripts, in particular in a contract such as «myctract», which uses the «run» function.
What are the arguments?
In Solidity, the argument is a transferred value of the code of call for the function carried out by an intelligent contract. For example, consider a simple contract with two functions: `Add a function (a uint256, b uint256) {}
andMultignate function (a uint256, b uint256) {}
.
Transfer of arguments to scripts
To transmit an argument to the script, you must use the correct syntax to transfer variables as functional arguments. In Solidity, this is generally done using the keyword «call» then the name of the argument.
For example, in the «Mycontract» contract:
`Solidity
MyContract contract {
// ... (other functions)
function of the function (
Address _Feerecipynt,
Uint256 _Feebase,
Uint256 _taxbase,
...
) public {
// use the arguments passed here
Call (_Feerecipynt, _feebase, _taxbase); // discuss the arguments as a function call
}
}
'
In this example, we provide "address" anduint256 ‘as arguments of the function to the» run «function.
Transfer of complex arguments
If you wish to transmit a complex structure of arguments, such as a card or an object, use the correct syntax:
`Solidity
function of the function (
Address _Feerecipynt,
uint256 [] _feebase,
uint256 [] [] _Taxbase,
...
) public {
// use the arguments passed here
}
'
Here, we pass "uint256 [] as the first argument `_feebase
uint256 [] [] as second argument_taxbase '.
Tips and best practices
- Always use the correct syntax to transmit arguments to the scripts.
- Make sure to use the right types of arguments (for exampleUint256 » instead of ‘Int’).
- Use «call» then the name of the argument to transmit the variables as a function call.
- Stay concise and focus on a task, because complex structures of arguments can make the code understanding difficult.
Examples of use
Here is an example of a contract that shows how to use the «execute» function with different types of arguments:
`Solidity
MyContract contract {
Add (Uint256 a, uint256 b) function (Uint256 b) Public {
// do something with the sum A and B
Uint256 result = A + b;
// passes the argument as a function call
Call (Result);
}
Multiplied function (Uint256 a, uint256 b) public {
// do something with the A and B product
Uint256 result = a * b;
// passes the argument as a function call
Call (Result);
}
}
` ‘
In this example, we use the «ADD» and «multiplication» functions to show how to transmit different types of arguments to the «run» function.
By following these guidelines and best practices, you can easily write effective and maintain solidity contracts that complex structures complex arguments.