Skip to main content

Simple wallet

An example of a basic wallet.

// SPDX-License-Identifier: MIT
pragma ever-solidity ^0.70.0;

/// @title Utility Errors
/// @notice Possible exception codes when interacting with contract
library Error {
uint8 constant CALLER_IS_NOT_OWNER = 100;
uint8 constant INVALID_DATA_STORAGE = 101;
}


/// @title Simple wallet
contract Wallet {

// Modifier that allows function to accept external call
// only if it was signed with contract owner's public key.
modifier ownerOnly {
// Check that inbound message was signed with owner's public key.
// Runtime function that obtains sender's public key.
require(msg.pubkey() == tvm.pubkey(), Error.CALLER_IS_NOT_OWNER);

// Runtime function that allows contract to process inbound messages spending
// its own resources (it's necessary if contract should process all inbound messages,
// not only those that carry value with them).
tvm.accept();
_;
}

/// @dev Contract constructor
constructor() ownerOnly {
// check that contract's public key is set
require(tvm.pubkey() != 0, Error.INVALID_DATA_STORAGE);
}

/// @dev Send to transfer EVER to the destination account
/// @param dest Transfer target address
/// @param value EVER value to transfer
function transfer(address dest, uint16 value) public view ownerOnly {
// Runtime function that allows to make a transfer with arbitrary settings.
dest.transfer(uint128(value) * 1e9, false, 1);
}

/// @dev Send transaction to another contract
/// @param dest Destination address
/// @param value Amount of attached NANOEVER
/// @param bounce Message bounce
/// @param flag Message flag
/// @param payload Tvm cell encoded payload, such as method call
function sendTransaction(
address dest,
uint128 value,
bool bounce,
uint8 flag,
TvmCell payload
) public view ownerOnly {
dest.transfer(value, bounce, flag, payload);
}

/// @dev destruct contract and send all money to target address
/// @param dest Transfer target address
function destruct(address dest) public ownerOnly {
selfdestruct(dest);
}
}

1008123500