ExecDelegatedTransfer
code:ExecDelegatedTransfer.js
const EthUtil = require('ethereumjs-util')
const Web3 = require('web3')
const WEB3_PROVIDER = 'wss://ropsten.infura.io/ws'
// トークンのABI
const TOKEN_ABI = [{"constant":true,"inputs":[],"name":"name","outputs":{"name":"","type":"string"},"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":{"name":"spender","type":"address"},{"name":"value","type":"uint256"},"name":"approve","outputs":{"name":"","type":"bool"},"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":{"name":"","type":"bool"},"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"rate","outputs":{"name":"","type":"uint256"},"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":{"name":"amount","type":"uint256"},"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":{"name":"","type":"uint8"},"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":{"name":"to","type":"address"},"name":"mint","outputs":{"name":"","type":"bool"},"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":{"name":"owner","type":"address"},"name":"balanceOf","outputs":{"name":"","type":"uint256"},"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":{"name":"delegatedTx","type":"bytes"},{"name":"sig","type":"bytes"},"name":"delegatedTransfer","outputs":{"name":"","type":"bool"},"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":{"name":"","type":"string"},"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":{"name":"to","type":"address"},{"name":"value","type":"uint256"},"name":"transfer","outputs":{"name":"","type":"bool"},"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"contractOwner","outputs":{"name":"","type":"address"},"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":{"name":"owner","type":"address"},{"name":"spender","type":"address"},"name":"allowance","outputs":{"name":"","type":"uint256"},"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":{"name":"owner","type":"address"},"name":"nonceOf","outputs":{"name":"","type":"uint256"},"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"},"name":"Transfer","type":"event"},{"anonymous":false,"inputs":{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"},"name":"Approval","type":"event"}] // トークンのコントラクトアドレス
const TOKEN_ADDRESS = '0x5c66afc60fa1fa2eeb5ea0ffae6236933571a9e0'
// トランザクション実行元のアドレスと秘密鍵
const ADDRESS = '0x4C22037a780d3a6171551539340186e0129E8c5E'
const PRIVATE_KEY_STRING = '0x46aa24456cc8686eb6a5070fb0e41c9a18b5c71e9597d958bf4626db7a02a41b'
// トークントランザクション
const TOKEN_TX = '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d02ab486cedc00002890228d4478e2c3b0ebf5a38479e3396c1d60740000000000000000000000005c66afc60fa1fa2eeb5ea0ffae6236933571a9e0000000000000000000000000'
// トークントランザクションの署名
const TOKEN_SIG = '0x2cd650f7e15e3840ea6a188ccd8586af157c5fc2e6da8074225cae9626fa8225283e46cfdacc6b42a45c1a66587af0934515b15e495878fbc1070476b6b5701d1b00000000000000000000000000000000000000000000000000000000000000'
// web3を初期化
const web3 = new Web3(WEB3_PROVIDER)
// トークンのスマートコントラクトを初期化
const token = new web3.eth.Contract(TOKEN_ABI, TOKEN_ADDRESS)
async function main() {
// 秘密鍵からウォレットを生成
web3.eth.accounts.wallet.add(PRIVATE_KEY_STRING);
// delegatedTransfer メソッドを実行
let options = {
from: ADDRESS,
gasPrice: 40000000000,
gas: 100000
}
let result = await token.methods.delegatedTransfer(TOKEN_TX, TOKEN_SIG).send(options)
console.log(result)
}
main()
説明