Created
June 8, 2020 06:13
-
-
Save harsh-98/8ce52eaffb131b49bebe15dd42f65c6f to your computer and use it in GitHub Desktop.
Trying to transfer MRC20 from one to other account on betav2 matic
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
const Web3 = require('web3'); | |
const BigNumber = require('bignumber.js'); | |
const fs = require('fs') | |
const { promisify } = require('util') | |
const readFileAsync = promisify(fs.readFile) | |
const options = { | |
transactionConfirmationBlocks: 2, | |
transactionBlockTimeout: 50, | |
} | |
if (typeof web3 !== 'undefined') { | |
web3 = new Web3(web3.currentProvider); | |
} else { | |
web3 = new Web3( | |
new Web3.providers.HttpProvider(`https://betav2.matic.network/api/eth_rpc`), options); //betav2-explorer.matic.network | |
}; | |
async function mrc20(){ | |
var address = "0x0000000000000000000000000000000000001010" | |
var obj = await readFileAsync('./localnet/code/contracts/build/contracts/MRC20.json') | |
obj = JSON.parse(obj) | |
// console.log(obj['abi']) | |
var myContract = new web3.eth.Contract(obj['abi'], address); | |
value = await myContract.methods.symbol().call(); | |
console.log(value) | |
value = await myContract.methods.balanceOf("0xaF9931D6EF3266AA36A37EE48EfDfAe102fE36b7").call() | |
console.log(value) | |
web3.eth.accounts.wallet.add('<private-key>'); | |
value =myContract.methods.transfer("0x7c183aF92294daf94902bC126eEFd8073c3e6e39", BigNumber("1e+18")).send({ | |
from: "0xaF9931D6EF3266AA36A37EE48EfDfAe102fE36b7", | |
value: web3.utils.toWei("1", "ether"), | |
gas: 100000 | |
}) | |
value.on('transactionHash', function(hash){ | |
console.log("hash",hash) | |
}) | |
.on('receipt', function(receipt){ | |
console.log("receipt", receipt) | |
}) | |
.on('confirmation', function(confirmationNumber, receipt){ | |
console.log(confirmationNumber, receipt) | |
}) | |
.on('error', function(error, receipt) { | |
console.log(error, receipt) | |
}); | |
} | |
mrc20() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment