If I create a smart contract and coin, can I for example some day close the contract and these coins are useless or can not be used for example? Is it possible or not?
-
Yes, you can implement a pausable token, or just suicide the contract – Raghav Sood Aug 14 '18 at 15:02
-
and if for example one exchanger is still my token listed and i suicide the token; close it and pause it, or like you say destruct completely the token what will happen with the tokens listed on the exchanger, he can still trade these tokens? – Perl Aug 14 '18 at 15:11
-
They can trade within the exchange, but no withdrawals or deposits will be possible. Any sane exchange would delist you if that happens. – Raghav Sood Aug 14 '18 at 15:16
3 Answers
If the contract supports such functionality, then yes.
You basically have two options:
1) Write code to deny usage of the contract based on some criteria. For example you can write a function which, when called, disables all other functionality in the contract.
2) Implement a self destruct function in the contract. This will remove the contract and it can no longer be used after that. This is the hammer approach and not very...subtle. Details here: http://solidity.readthedocs.io/en/v0.4.24/introduction-to-smart-contracts.html#self-destruct
- 29,391
- 3
- 20
- 57
-
and if for example one exchanger is still my token listed and i suicide the token; close it and pause it, or like you say destruct completely the token what will happen with the tokens listed on the exchanger, he can still trade these tokens? – Perl Aug 14 '18 at 15:11
-
Please don't double-post your questions. This was answered above. – Lauri Peltonen Aug 14 '18 at 15:23
The Open-Zeppelin library for Solidity has a few life-cycle contracts which handle scenarios like the one you describe. You can find them all here:
https://github.com/OpenZeppelin/openzeppelin-solidity/tree/master/contracts/lifecycle
Destructible.sol
This is the one that most closely resembles what you are looking to do, and supports two functions:
function destroy() public onlyOwner {
selfdestruct(owner);
}
function destroyAndSend(address _recipient) public onlyOwner {
selfdestruct(_recipient);
}
First it takes advantage of another Open-Zeppelin library called Ownable.sol which allows a contract to have a specified address as the owner of the contract. By default, it is the contract creator.
Then Destructible.sol enables the owner to specifically destroy the contract, either sending any remaining ETH balance to themselves or a specific recipient.
- 8,008
- 4
- 19
- 38
pragma solidity ^0.5.8;
// Set the contract name "Bank_A"
// Set numbers of clients who opening account in Bank_A
// Get the balances and address of clients
// Define the address of the BankA owner
contract Bank_A {
uint8 private clientCount;
mapping (address => uint) private balances;
address owner;
// Log the event about a deposit being made by an address and its amount
event LogDepositMade(address indexed accountAddress, uint amount);
// Constructor is "payable" so it can receive the initial funding of 10,
// required to reward the first client 1 ether
constructor() public payable {
require(msg.value == 10 ether, "10 ether initial funding required");
/* Set the owner to the creator of this contract */
owner = msg.sender;
clientCount = 0;
}
/// @notice a customer open an account in bank_A,
/// giving the first customer 1 ether as reward
/// @return The balance of the customer after enrolling
function enroll() public returns (uint) {
if (clientCount < 1) {
balances[msg.sender] = 1 ether;
clientCount += 1;
}
return balances[msg.sender];
}
/// @notice Deposit ether into bank, requires method is "payable"
/// @return The balance of the user after the deposit is made
function deposit() public payable returns (uint) {
balances[msg.sender] += msg.value;
emit LogDepositMade(msg.sender, msg.value);
return balances[msg.sender];
}
/// @notice Withdraw ether from bank
/// @return The balance remaining for the user
function withdraw(uint withdrawAmount) public returns (uint remainingBal) {
// Check enough balance available, otherwise just return balance
if (withdrawAmount <= balances[msg.sender]) {
balances[msg.sender] -= withdrawAmount;
msg.sender.transfer(withdrawAmount);
}
return balances[msg.sender];
}
/// @notice Just reads balance of the account requesting, so "constant"
/// @return The balance of the user
function balance() public view returns (uint) {
return balances[msg.sender];
}
/// @return The balance of the Bank_A contract
function depositsBalance() public view returns (uint) {
return address(this).balance;
}
///@only the bank owner can close the bank
function closebank() public view return(unit) {
}
}
-
Can you add more details? like an explanation what are you trying to do to answer the question. – Ismael Sep 19 '21 at 18:27