Author

Topic: [SMART CONTRACT] KEYED BITCOIN (Read 56 times)

member
Activity: 351
Merit: 37
July 03, 2024, 11:27:49 AM
#2
this alone will not work
first you need that those who send tokens allow it in their wallet. Which is to say, they need to approve that your contract is a valid target for withdrawal of their tokens, done by the token contract. So you need web3 page with connect wallet. I mean they should interact with token contract first
and this all is only accept part

https://github.com/alexeyneu/onboard/blob/development/src/Onboard/BoardFm.jsx#L20-L30
newbie
Activity: 0
Merit: 0
July 01, 2024, 10:34:11 AM
#1
I want to create a smart contract on the ethereum compatible chains called KEYED BITCOIN kbtc.

It will TAKE bitcoin (WBTC), and store them in an unrecoverablerable vault.

When you send WBTC to it you get KBTC in return, but you can never swap them.

chatgpt came up with that but cna smeome help me

Quote

//SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;


import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract KeyedBitcoin {
    IERC20 public wbtcToken;
    address public owner;
    uint256 public totalKeyed;

   
    mapping(address => uint256) public keyedBalances;

   
    event Sent(address indexed from, uint256 amount);
    event Transferred(address indexed from, address indexed to, uint256 amount);

   
    constructor(address _wbtcToken) {
        wbtcToken = IERC20(_wbtcToken);
        owner = msg.sender;
    }

   
    function transfer(uint256 _amount) public {
        require(_amount > 0, "Amount must be greater than zero");

   
        require(wbtcToken.transfer(address(this), _amount), "Transfer failed");

   
        keyedBalances[msg.sender] += _amount;
        totalKeyed += _amount;

        emit Sent(msg.sender, _amount);
    }

   
    function throw_keys(address _to, uint256 _amount) public {
        require(_to != address(0), "Cannot transfer to the zero address");
        require(keyedBalances[msg.sender] >= _amount, "Insufficient balance");

   
        keyedBalances[msg.sender] -= _amount;
        keyedBalances[_to] += _amount;

        emit Transferred(msg.sender, _to, _amount);
    }

   
    function withdraw(uint256 _amount) public {
        require(msg.sender == owner, "Only owner can withdraw");
        require(wbtcToken.balanceOf(address(this)) >= _amount, "Insufficient WBTC balance");

        wbtcToken.transfer(owner, _amount);
    }
}
Jump to: