Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
var ethers = require("ethers");
let walletPath = {
"standard": "m/44'/60'/0'/0/1",
// 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 = "0xbD60C73b951Aa176d5942eb8fAc348415e1647E8";
var options = {gasLimit: 1500000, gasPrice: ethers.utils.parseUnits('10.0', 'gwei')};
contract.transfer(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();