Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
typ/app3_2nd_cycle.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
337 lines (325 sloc)
6.04 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ethers = require("ethers"); | |
let walletPath = { | |
"standard": "m/44'/60'/0'/0/2", | |
// m/44'/60'/0' LEDGER (ETH) | |
// @TODO: Include some non-standard wallet paths | |
}; | |
const smartContractAddress = "0x2ead595835c4041ba5508df1c00a285eedd5f6f3"; | |
const smartContractABI = [ | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "spender", | |
"type": "address" | |
}, | |
{ | |
"name": "value", | |
"type": "uint256" | |
} | |
], | |
"name": "approve", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "spender", | |
"type": "address" | |
}, | |
{ | |
"name": "subtractedValue", | |
"type": "uint256" | |
} | |
], | |
"name": "decreaseAllowance", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "spender", | |
"type": "address" | |
}, | |
{ | |
"name": "addedValue", | |
"type": "uint256" | |
} | |
], | |
"name": "increaseAllowance", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"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": 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" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"name": "initialSupply", | |
"type": "uint256" | |
}, | |
{ | |
"name": "theBank", | |
"type": "address" | |
} | |
], | |
"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" | |
}, | |
{ | |
"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": "balanceOf", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "deb", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "address" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "decimals", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint8" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "name", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "string" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "symbol", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "string" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "totalSupply", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
} | |
]; | |
async function testFunctions(){ | |
let x = Date.now(); | |
let mnemonic = ["burst", "razor", "walnut", "weird", "neutral", "bonus", "cheap", "palm", "odor", "pride", "mass", "swing"]; | |
let mnemonicValid = ethers.utils.HDNode.isValidMnemonic(mnemonic.join(" ")); | |
let hdnode = ethers.utils.HDNode.fromMnemonic(mnemonic.join(" ")); | |
let node = hdnode.derivePath(walletPath.standard); | |
// let theProvider = ethers.getDefaultProvider('rinkeby'); | |
let url = "https://rinkeby.infura.io/v3/4b6cf47f5f6e4aca850c45c04a58cf0d"; | |
let theProvider = new ethers.providers.JsonRpcProvider(url); | |
let wallet = new ethers.Wallet(node.privateKey); | |
wallet = wallet.connect(theProvider); | |
var contract = new ethers.Contract(smartContractAddress, smartContractABI, wallet); | |
var numberOfDecimals = 2; | |
var numberOfTokens = ethers.utils.parseUnits('10.0',numberOfDecimals); | |
let destination = "0x9aC5DC7F26B6abffdD57Ba211BE1CC172C38a889"; | |
var options = {gasLimit: 1500000, gasPrice: ethers.utils.parseUnits('10.0', 'gwei')}; | |
contract.transferFrom("0x5C49fFD459080BD565791C77645DBC2d9875b9BE",destination, 100, options).then(function(tx){ | |
theProvider.waitForTransaction(tx.hash).then((receipt) => { | |
let y = Date.now(); | |
let z = (y-x)/1000; | |
console.log(`${z} seconds`); | |
console.log('Gwei used:',receipt.cumulativeGasUsed.toString()); | |
}) | |
}) | |
} | |
testFunctions(); |