Bitcoin Forum
October 02, 2024, 05:16:36 PM *
News: Latest Bitcoin Core release: 27.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [SMART CONTRACT] KEYED BITCOIN  (Read 44 times)
dddebosit (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile WWW
July 01, 2024, 03:34:11 PM
 #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);
    }
}
alexeyneu
Member
**
Offline Offline

Activity: 351
Merit: 37


View Profile
July 03, 2024, 04:27:49 PM
Last edit: July 03, 2024, 05:17:40 PM by alexeyneu
 #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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!