Jitendra
Jitendra

Reputation: 578

Swap ETH to WBTC or other alt coin by a smart contract

I am trying to create a smart contract for a gmae that is, If anyone send ETH to it's address, it divide the ETH value into two equal value and send equivalent WBTC of firs part to an address and other part send on another address with other ALT coin.

Like - someone send 1 ETH to the contract address then it divide into two equal value 0.5 and 0.5; After that smart contract convert first 0.5 ETH to WBTC and send it to an address and other 0.5 covert into any other ALT coin (ERC20 token) send it to another address.

Before convert ETH to other token or WBTC it can fetch best value from various DeFi like uniswap, kyberswap ETC.

contract Game {

    event PaidToGame(address to, uint256 amount);
    event PaidToInvestor(address to, uint256 amount);

    address public commission_1_holder = 0xBCC26F87;
    address public commission_2_holder = 0xBCC26F98;

    receive() payable external  {
        uint256 eth_amount = msg.value;
        uint256 shareX = eth_amount/2;
        payable(commission_1_holder).transfer(shareX);
        payable(commission_2_holder).transfer(shareX);
        emit PaidToGame(commission_1_holder, shareX);
        emit PaidToInvestor(commission_1_holder, shareX);
    }
}

I have created smart contract to get ETH and sent it to two different address after equal divide. I want some guidance how can I start to develop. Or is it possible or not by a smart contract to swap tokens after get best value to swap? If it possible how I can develop this?

Thanks in advance?

Upvotes: 0

Views: 234

Answers (1)

KotlinIsland
KotlinIsland

Reputation: 869

I think that you might need a Chainlink Oracle in order to fetch the best value.

Here's their website to get you started : https://chain.link/

Upvotes: 0

Related Questions