我正在尝试构建一个智能合约,并继承一些函数来交换ERC20代币。
这是我的问题?
问题A: 是否可能将ERC20代币转移到智能合约余额中? 请提供一个例子, 例如:我们可以创建一个函数将ETH发送到智能合约中。
function contribute() external payable {}
//It will allow us to send ETH to smart contract balance,but how to send,for example, "BAND" token
//to smart contract balance?
问题B: 如果A是可能的,如何获得合约的代币余额? 即,我们可以通过此函数获得合约的ETH余额:
// Get ETH balance
function getBalance() external view returns(uint) {
return address(this).balance;
}
// How to return contract's BAND balance, if A is possible ...
问题 C:
如果“A”是可能的,如何使用Uniswap或Sushiswap API将交换成BAND/ETH流动性池?
在服务器端使用NodeJS处理该过程好还是在solidity中实现?
完整的智能合约代码:
pragma solidity ^0.5.11;
contract SwapTest {
address public manager;
constructor() public {
manager = msg.sender;
}
modifier OnlyManager() {
require(msg.sender == manager);
_;
}
// Add funds to contract
function contribute() external payable {}
// Get ETH balance
function getBalance() external view returns(uint) {
return address(this).balance;
}
// Send provided amount of WEI to recipient
function sendEther (address payable recipient, uint weiAmount) external OnlyManager{
recipient.transfer(weiAmount);
}
// Send contract balance to recipient
function withdrawBalance (address payable recipient) external OnlyManager{
recipient.transfer(address(this).balance);
}
}
期待收到你们的回复,先行谢过。