我有两个ERC20代币。合同设计为标准ERC20。这里有两个代币作为例子-
AUDC --> Contract Address: (0xContractAUDC)
Wallet Address: (0xWalletAUDC)
DAI --> Contract Address: (0xContractDAI)
Wallet Address: (0xWalletDAI)我想把一些DAI从钱包0xWalletDAI转到0xWalletAUDC,作为回报,我得到了转换后的AUDC (我有两个钱包的私钥)。
寻找一些帮助,以了解如何实现这一点。如果需要的话,我会尽力提供更多的信息。
我正在使用ethers.js v4.0与区块链交互。
发布于 2019-09-28 08:05:59
使用ether.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);https://ethereum.stackexchange.com/questions/76191
复制相似问题