Ethereum: Sépola smart contract – withdrawal function
I deployed a basic intelligent contract for the sepsolian test network, but unhappy get up with my watlet with a Watrawrawal function. After series adtams, I let myself be and wondered and wondered if I made deployment or duck configuration errors.
In this article, I will describe the steps that I am going to have a Sepora intelligent contract, the problems that are inspections that are intelligences for the besses.
Deployment of the smart contract
To pay the intelligent contract, I am used the very close suite for the development of solidity. The current was created by establishing a soft token ERC-20 on a smart contract, which is suitable for sepsolia of test network.
Here is an extract from my contract code:
`Solidity
Pragma Solidity ^ 0.8,0;
Sepola contract
approach the public owner;
Uitt256 public balance;
Builder () Public {
owner = msg.sender;
balance = 10 ethers;
}
The public office (up to 256 Amunt) public {
require (msg.sender = owner, "only the best can call this function");
balance + = Amunt;
}
Withdrawal function (UID256 amunt) public {
require (upstream <= balance, "insufficient funds");
Balance - = Amunt;
}
}
re
To pay the contract on the Sépsolia, I used the trufle migration command:
bash
migrate truffles -sepola
re
This deployed the intelligent contract for them from the Sepsolia test network.
Test withdrawals
After having deployed the contract and having put it in place in SépSolie, I gave the finished to a contract also a seed of a single witrawal function. Here's how I test it:
Solidity
Pragma Solidity ^ 0.8,0;
Sepola contract
approach the public owner;
Uitt256 public balance;
Builder () Public {
owner = msg.sender;
balance = 10 ethers;
}
The public office (up to 256 Amunt) public {
require (msg.sender = owner, "only the best can call this function");
balance + = Amunt;
}
Function withdraw (UID256 amunt) public {
require (Mont <= balance, "insufficient funds");
Balance - = Amunt;
}
}
Sepolatest contract
Sepoli public Sépola;
Builder () Public {
Sepola = New Sepiola ();
}
The function of Testhwrawal () Public payable {
THE
Recepientaddress address = 0x ... (load with your house walladdress);
// calls them with an ammission function
Sepoli.withdraw (10 ethers); // Tent with a 10 ether
// says you without
Affirm (sepoa.balance> = 10);
}
}
re
In this test, I deployed a new contract called "sepilate" and created Sépsolia. The function created of an end of the eveningTestwrawal is mine in which you have an endless plunder is the intelligent sepolitic contract.
Farter routing the test, I was delighted to see them theirs who were a bottle! The balance has 10 ether increased by 10 ether which I call the "withdrawal" function.
The problem
Howver, I quickly encountered a problem: despite a success with a 10 ether in my tests, I received an "insufficient fund" of the Watlet de Sepola contract. It is the evening of these things that even that the way in which success is mine.
Pasting it as a review my code and experimenting with the differentiation scenario, I discovered that the WACT show the fact that I usedBESTION (upstream <= balance)" in these them. This condition will assure you that you will have a development balance.