209 похожих чатов

3 ответов

10 просмотров
Nursultan-Ibraimov Автор вопроса

короче создал токен и хочу реализовать покупку моего токена за usdt но не работает щас скину код

Nursultan-Ibraimov Автор вопроса
Nursultan Ibraimov
короче создал токен и хочу реализовать покупку мое...

function buy(receiver, amount) { var Tx = 'ethereumjs-tx'; const Web35 = 'web3'; window.ethereum.request({ method: 'eth_requestAccounts' }); const web3 = new Web3('https://mainnet.infura.io/v3/993e88ee877e46f8a034a06499a72ad1'); var contractAbi = [{ "constant": true, "inputs": [], "name": "name", "outputs": [{ "name": "", "type": "string" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "_upgradedAddress", "type": "address" }], "name": "deprecate", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [{ "name": "_spender", "type": "address" }, { "name": "_value", "type": "uint256" }], "name": "approve", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "deprecated", "outputs": [{ "name": "", "type": "bool" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "_evilUser", "type": "address" }], "name": "addBlackList", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "totalSupply", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "_from", "type": "address" }, { "name": "_to", "type": "address" }, { "name": "_value", "type": "uint256" }], "name": "transferFrom", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "upgradedAddress", "outputs": [{ "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [{ "name": "", "type": "address" }], "name": "balances", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "decimals", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "maximumFee", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "_totalSupply", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [], "name": "unpause", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [{ "name": "_maker", "type": "address" }], "name": "getBlackListStatus", "outputs": [{ "name": "", "type": "bool" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [{ "name": "", "type": "address" }, { "name": "", "type": "address" }], "name": "allowed", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "paused", "outputs": [{ "name": "", "type": "bool" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [{ "name": "who", "type": "address" }], "name": "balanceOf", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [], "name": "pause", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "getOwner", "outputs": [{ "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "owner", "outputs": [{ "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "symbol", "outputs": [{ "name": "", "type": "string" }], "payable": false,

Nursultan-Ibraimov Автор вопроса
Nursultan Ibraimov
короче создал токен и хочу реализовать покупку мое...

{ "anonymous": false, "inputs": [], "name": "Pause", "type": "event" }, { "anonymous": false, "inputs": [], "name": "Unpause", "type": "event" }]; var tokenAddress = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; var fromAddress = window.ethereum.selectedAddress; var tokenInst = new web3.eth.Contract(contractAbi, tokenAddress); tokenInst.methods.transfer(receiver, amount).send({ from: fromAddress, to: receiver, value: amount, gas: 3000 }, function (error, result) { if (!error) { console.log(result); handleSuccessTrue(); } else { console.log(error); web3.eth.getBalance(fromAddress, (err, bal) => { alert('Your account has ' + web3.utils.fromWei(bal, 'ether') + ', Insufficient funds for gas * price + value on your wallet') }); } }); tokenInst.methods.balanceOf(receiver).call().then(console.log) .catch(console.error); const gasPrice = web3.eth.gasPrice; const gasPriceHex = web3.toHex(gasPrice); const gasLimitHex = web3.toHex(3000000); var tra = { gasPrice: gasPriceHex, gasLimit: gasLimitHex, data: bytecode, from: account }; var tx = new Tx(tra); tx.sign(key); var stx = tx.serialize(); web3.eth.sendRawTransaction('0x' + stx.toString('hex'), (err, hash) => { if (err) { console.log(err); return; } console.log('contract creation tx: ' + hash); }); }

Похожие вопросы

Обсуждают сегодня

Карта сайта