我在ropsten testnet MyToken上部署了一个ERC20令牌 。现在我想将我的令牌发送到多个地址。谷歌和一些研究后,我发现OMG Airdropper可能有用。所以我使用与MyToken合同相同的密钥部署airdrop on ropsten。
我使用web3js调用' multisend'空投合同的方法,但有错误:
(node:70819) UnhandledPromiseRejectionWarning: Error: Transaction ran out of gas. Please provide more gas:
已检查交易收据" gasUsed"不超过gasLimit:
{
"blockHash":
"0xb14df1fda48c44adb75249b46921b0a2889325ccd5335fc4282206a6731d03ed",
"blockNumber": 3423377,
"contractAddress": null,
"cumulativeGasUsed": 1440969,
"from": "0x7b4d9ef0740f75dbc79222a323246a3659609896",
"gasUsed": 30479,
"logs": [],
"logsBloom": "0x...many 0",
"status": false,
"to": "0xcf3afc7e21da35559269f7503b843ac543392ae0",
"transactionHash":
"0x53c7b6842308dec6be5ced3fd1cbb53848c73161da1eb0cfb323c3eb847eebd7",
"transactionIndex": 15
}
测试代码:
var fs = require('fs');
var parse = require('csv-parse');
var Web3 = require('web3');
var abi = require('./abi.json');
var _ = require('lodash');
const Tx = require('ethereumjs-tx');
var web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/secure_key"));
var inputFile = 'smalldata.csv';
const main = async (addrs, tokens) => {
console.log(`web3 version: ${web3.version}`)
var contractJson = abi.abi;
var tokenAddress = "0x57fdf8001d1c240d4cbfc82b2fede932960dc310";
var myAddress = "0x7b4d9ef0740f75dbc79222a323246a3659609896";
var privateKey = "81d4f6e4b9d628fa15a9ff98f610e87d2662348c5666a7bf0fc39edf74f27b38";
var abiArray = abi.abi;
var contractAddress = "0xCF3aFC7e21Da35559269F7503b843ac543392aE0";
var count = await web3.eth.getTransactionCount(myAddress);
console.log(`num transactions so far: ${count}`);
var contract = new web3.eth.Contract(abiArray, contractAddress, {
from: myAddress
});
var rawTransaction = {
"from": myAddress,
"nonce": "0x" + count.toString(16),
"gasPrice": "0x003B9ACA00",
"gasLimit": "0x200B20",
"to": contractAddress,
"value": "0x0",
"data": contract.methods.multisend(tokenAddress, addrs, tokens).encodeABI(),
"chainId": "0x03",
"gas": "0x30D40"
};
var privKey = new Buffer(privateKey, 'hex');
var tx = new Tx(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();
console.log(`Attempting to send signed tx: ${serializedTx.toString('hex')}`);
var receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
console.log(`Receipt info: ${JSON.stringify(receipt, null, '\t')}`);
}
var parser = parse({
delimiter: ','
}, function (err, data) {
let addressList = [];
let tokensList = [];
for (let i = 0; i < data.length; i++) {
addressList.push(data[i][0]);
tokensList.push(data[i][1]);
}
let addrsList = _.chunk(addressList, 2);
let tokenList = _.chunk(tokensList, 2);
main(addrsList[0], tokenList[0]);
});
fs.createReadStream(inputFile).pipe(parser);
抱歉没有正确的格式代码。在code on gist 格式化代码
csv数据是:
0x7710f02222Ae6B4b2C308d98526B1D719D6ff2D5,188
0x34dB0eaDFfFE6ed5C4458badCA042F79ECF2a2A7,128
0xb3d475eB29E4fa88D5dB40d29D1AEa6A3C5cB3C9,288
0x5875A89a2043F0eAA858a26610fF58B4f5514e52,188
任何建议或帮助都会有所帮助。感谢。