Created
November 3, 2019 19:32
-
-
Save johngrantuk/453de92c28bfae6848ebe13e3e62c74f to your computer and use it in GitHub Desktop.
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
/* | |
I was doing this using the Klaytn network which is basically a centralised Ethereum clone. | |
The following code would work on Ethereum with a bit of a change - i.e. Caver to Web3 | |
*/ | |
/* | |
Example contract artificat addition: | |
"networks": { | |
"8217": { | |
"events": {}, | |
"links": {}, | |
"address": "0x3973e66b65b0BdE40aDC747921fc9e5A74D11c55", | |
"transactionHash": "0x31195434ee44bb48e5209b6103a2cb1a68dfae3c49bb1cd32f7ea5eab9dfd957" | |
} | |
} | |
*/ | |
const Caver = require('caver-js'); // Swap for Web3.js | |
const caver = new Caver('https://api.cypress.klaytn.net:8651'); // Swap for Infura or similar. | |
const fs = require('fs'); | |
const HackVibeContract = JSON.parse(fs.readFileSync("./client/src/contracts/HackVibes.json")); // Artifact | |
const sender = caver.klay.accounts.wallet.add(Address); | |
const payer = caver.klay.accounts.wallet.add(Address, PrivateKey); | |
async function run() { | |
// Main deploy actions. | |
// make sure `data` starts with 0x | |
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({ | |
type: 'FEE_DELEGATED_SMART_CONTRACT_DEPLOY', // This wouldn't be used in Ethereum | |
from: sender.address, | |
data: HackVibeContract.bytecode, // From artifact pre-compile, $ truffle compile | |
gas: '3000000', | |
value: 0, | |
}, sender.privateKey); | |
// signed raw transaction | |
console.log("Raw TX:\n", senderRawTransaction); | |
// send fee delegated transaction with fee payer information | |
caver.klay.sendTransaction({ | |
senderRawTransaction: senderRawTransaction, | |
feePayer: payer.address | |
}) | |
.on('transactionHash', function (hash) { | |
console.log(">>> tx_hash for deploy =", hash); // | |
}) | |
.on('receipt', function (receipt) { | |
console.log(">>> receipt arrived: ", receipt); // Note this output | |
}) | |
.on('error', function (err) { | |
console.error(">>> error: ", err); | |
}); | |
} | |
async function testContract(address) { | |
// Useful for a test interaction | |
console.log('Testing Contract...') | |
// Reference to the deployed contract | |
var contract = await new caver.klay.Contract(HackVibeContract.abi, HackVibeContract.networks['8217']); | |
// Assert initial account balance, should be 100000 | |
const balance1 = await contract.noCommitments.call(); | |
console.log(balance1) | |
} | |
//run(); | |
testContract(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment