你可以试试这段代码
transferTokensTo: function(contract, address_from, address, tokens) {
return new Promise(function(resolve, reject) {
contract.methods.decimals().call().then(function (result) {
var decimals = result;
console.log("Token decimals: " + decimals);
var amount = tokens * Math.pow(10, decimals);
console.log('Transfer to:', address);
console.log('Tokens: ' + tokens + " (" + amount + ")");
contract.methods.transfer(address, amount).send({
from: address_from,
gas: 150000
}).on('transactionHash', function (hash) {
console.log('\n[TRANSACTION_HASH]\n\n' + hash);
}).on('confirmation', function (confirmationNumber, receipt) {
console.log('\n[CONFIRMATION] ', confirmationNumber);
resolve(receipt);
}).on('receipt', function (receipt) {
console.log('\n[RECEIPT]\n\n', receipt);
// TODO: process receipt if needed
}).on('error', function (error) {
console.log('\n[ERROR]\n\n' + error);
reject(error);
}).then(function (done) {
console.log('\n[DONE]\n\n', done);
});
});
});
}