Я попробовал код ниже, но он не работает хорошо. Мне нужно перевести токен erc20 на другой аккаунт.
Некоторая информация, которую я использовал Smart Contract: https://ropsten.etherscan.io/token/0x25dbda28b6ca5fdfa9e421a887b4395390215adb
<script src="js/web3.min.js"></script>
<script type="text/javascript" src="js/ethereumjs-tx-1.3.3.js"></script>
<script type="text/javascript">
if (typeof web3 !== 'undefined') {
var web3 = require('web3');
const Tx = require('ethereumjs-tx').Transaction
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/Key"));
}
web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/Key"));
var contractAddress = '0x25DBda28B6cA5fdfa9E421a887B4395390215ADB'
var membersatu = '0xC0401aab87b9c0AFD47b67AB117c03e62c4F4fEd'
var abiArray = myABIJson;
var token = new web3.eth.Contract(abiArray, contractAddress);
// mendapatkan nama kontrak
// console.log(token.methods.name().call();
console.log(token.methods.name().call());
console.log(token.methods);
var count = web3.eth.getTransactionCount("0x25DBda28B6cA5fdfa9E421a887B4395390215ADB");
var rawTransaction = {
"from": "0x25DBda28B6cA5fdfa9E421a887B4395390215ADB",
"nonce": web3.utils.toHex(count),
"gasPrice": "0x04e3b29200",
"gasLimit": "0x7458",
"to": '0xC0401aab87b9c0AFD47b67AB117c03e62c4F4fEd',
"value": 10,
};
var privKey = new Buffer('MyPrivateKey', 'hex');
var tx = new Tx(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
if (!err)
console.log(hash);
else
console.log(err);
});
</script>