Last active
May 9, 2020 19:33
-
-
Save JTraversa/8b98aa7aab0069a45b354bf1d7c7ec8a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
if (window.ethereum) { | |
var web3 = new Web3(window.ethereum); | |
window.ethereum.enable();} | |
const childChain = new ChildChain({ watcherUrl: "https://watcher-info.ropsten.v1.omg.network" }); | |
account = getAccounts(function(result) { | |
document.getElementById("useraddress").innerHTML = result[0]; | |
}); | |
async function transfer () { | |
// We want to pay the fee in ETH, so we have to fetch the ETH fee amount from the Watcher | |
const allFees = await childChain.getFees() | |
const feesForTransactions = allFees['1'] | |
const { amount: ethFeeAmount } = feesForTransactions.find(i => i.currency === OmgUtil.transaction.ETH_CURRENCY) | |
const _utxos = await childChain.getUtxos("0x00fE460A15B49d09F39b057D0f1A7B9444F4F2BE"); | |
console.log(_utxos); | |
// Create the transaction body | |
const transactionBody = OmgUtil.transaction.createTransactionBody({ | |
fromAddress: "0x00fE460A15B49d09F39b057D0f1A7B9444F4F2BE", | |
fromUtxos: _utxos, | |
payments: [ | |
{ | |
owner: "0x84b5ce3eA8CDC1B19Ea1768F1C4075b6937b483b", | |
currency: '0x0000000000000000000000000000000000000000', | |
amount: '1' | |
} | |
], | |
fee: { | |
currency: OmgUtil.transaction.ETH_CURRENCY, | |
amount: ethFeeAmount | |
}, | |
metadata: "data" | |
}); | |
// Type, sign, and submit the transaction to the Watcher | |
const typedData = OmgUtil.transaction.getTypedData(transactionBody, "0x96d5d8bc539694e5fa1ec0dab0e6327ca9e680f9") | |
const privateKeys = new Array(transactionBody.inputs.length).fill("0xREDACTED") | |
console.log(privateKeys); | |
const signatures = childChain.signTransaction(typedData, privateKeys) | |
const signedTxn = childChain.buildSignedTransaction(typedData, signatures) | |
childChain.submitTransaction(signedTxn) | |
} | |
function getAccounts(callback) { | |
web3.eth.getAccounts((error,result) => { | |
if (error) { | |
console.log(error); | |
} else { | |
callback(result); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment