Blockchain 将ERC20令牌与其他ERC20令牌交换

Blockchain 将ERC20令牌与其他ERC20令牌交换,blockchain,ethereum,solidity,ether,Blockchain,Ethereum,Solidity,Ether,我有两个ERC20代币。合同设计为标准ERC20。这里有两个令牌作为示例- AUDC --> Contract address: (0xContractAUDC) Wallet Address: (0xWalletAUDC) DAI --> Contract address: (0xContractDAI) Wallet Address: (0xWalletDAI) 我想将一些DAI从钱包0xWalletDAI转移到0xWalletAU

我有两个ERC20代币。合同设计为标准ERC20。这里有两个令牌作为示例-

AUDC --> Contract address: (0xContractAUDC)
         Wallet Address:   (0xWalletAUDC)
DAI  --> Contract address: (0xContractDAI)
         Wallet Address:   (0xWalletDAI)
我想将一些DAI从钱包
0xWalletDAI
转移到
0xWalletAUDC
以接收转换后的AUDC作为回报(我有两个钱包的私钥)

正在寻找一些帮助,以了解如何实现这一点。如果需要,我会尽量提供更多信息


我正在使用
ethers.js v4.0
与区块链交互。

我找到了使用ethers.js实现这一点的解决方案-

const ethers = require('ethers');

let provider = ethers.getDefaultProvider();

// WALLETS
const DAIUserWalletObj = new ethers.Wallet(DAIUserPrivateKey, provider);
const AUDCWalletObj = new ethers.Wallet(AUDCPrivateKey, provider);

//CONTRACTS
const contractDAI = new ethers.Contract(DAIContractAddress, DAIContractABI, provider);
constractDAI = contractDAI.connect(DAIUserWalletObj);
const contractAUDC = new ethers.Contract(AUDCContractAddress, AUDCContractABI, provider);
contractAUDC = contractAUDC.connect(AUDCWalletObj);

let overRide = { gasLimit: 7500000 }
let numDAITokens = 20;  // Just for example
let numOfAUDCTokens = 40; // Just for example
const receipt1 = await contractDAI.transfer(AUDCContractAddress, numDAITokens, overRide);
const receipt2 = await contractAUDC.transfer(DAIUserWalletAddress, numOfAUDCTokens, overRide);
console.log(receipt1);
console.log(receipt2);

你是想进行分散交换还是集中交换?@VitalyMigunov我在寻找集中交换。这个问题太模糊了。因为实际上有很多方法可以做到这一点,但是如果你想完全集中化,那么制作第三个交换钱包就更容易了,在这里你可以离线跟踪其中的所有代币