Avoid transferring money to non-existent accounts
Non-existent account transfers and penalties
In addition to illegal operations, transferring VS/VRC10 to a non-existent account will also result in a full fine of fee_limit. Users usually set the fee limit to 1000 VS (upper limit), so this is a heavyweight penalty, and if the user tries to automatically retry the operation, the cost is higher.
Examples of penalized contracts
Transfer VS to a non-existent/invalid account
pragma solidity ^0.4.23;
contract Invalid {
function transAddr() public payable {
address invalid = 0x1234abcd;
invalid.transfer(10 vs);
}
function transAddr2(address addr) public payable {
addr.transfer(10 vs);
}
}
In the above example, transAddr always fails and consumes fee_limit. In the more common transAddr2 case, developers should ensure that addr is pre-verified in VisionWeb or some other existing address. Otherwise, the user will pay a fee_limit fine.
Transfer VS to yourself
pragma solidity ^0.4.23;
contract Self {
function transAddr() public payable {
address(this).transfer(10 vs);
}
function transAddr2(address addr) public payable {
addr.transfer(10 vs);
}
function transAddr3(address addr) public payable {
require(addr != address(this));
addr.transfer(10 vs);
}
}
Similarly, transAddr will always be punished by fee_limit. If addr is the contract address itself, transAddr2 will not be able to transfer money by itself. transAddr3 prevents self-transfer penalties, but still faces the aforementioned non-existent account issues.
Transfer VRC10 tokens to a non-existent/invalid account
pragma solidity ^0.4.24;
contract VRC10 {
function sendBalance(address to) public payable {
vrcToken id = msg.tokenid;
uint256 value = msg.tokenvalue;
to.transferToken(value, id);
}
function sendBalance2() public payable {
vrcToken id = msg.tokenid;
uint256 value = msg.tokenvalue;
address(this).transferToken(value, id);
}
}
Similar to the VS transfer above, if the transfer is made to a non-existent account, sendBalance must fail and be fined by fee_limit. The self-transfer case sendBalance2 will also result in fee_limit fines.
Updated over 3 years ago