-
-
Save aeharvlee/e47223dd1c3e6f28a490ff02fa9d5a49 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
const path = require('path') | |
const dotenv = require('dotenv') | |
const Caver = require('caver-js') | |
let nodeApiUrl = 'https://node-api.klaytnapi.com/v1/klaytn' // e.g. 'https://node-api.klaytnapi.com/v1/klaytn' | |
let accessKeyId = '' // e.g. 'KASK1LVNO498YT6KJQFUPY8S' | |
let secretAccessKey = '' // e.g. 'aP/reVYHXqjw3EtQrMuJP4A3/hOb69TjnBT3ePKG' | |
let chainId = '1001' // e.g. '1001' or '8217' | |
let deployerAddress = '' // e.g. '0xeb709d59954f4cdc6b6f3bfcd8d531887b7bd199' | |
let deployerPrivateKey = '' // e.g. '0x39a6375b608c2572fadb2ed9fd78c5c456ca3aa860c43192ad910c3269727fc1' | |
async function main() { | |
try { | |
loadEnv() | |
await run() | |
} catch (err) { | |
console.error(err) | |
} | |
} | |
main() | |
async function run() { | |
// In the caver, almost everything starts with the caver. Let's create a caver instance | |
const option = { | |
headers: [ | |
{ | |
name: 'Authorization', | |
value: `Basic ${Buffer.from(`${accessKeyId}:${secretAccessKey}`).toString('base64')}`, | |
}, | |
{ name: 'x-chain-id', value: chainId }, | |
], | |
} | |
const caver = new Caver(new Caver.providers.HttpProvider(nodeApiUrl, option)) | |
const abi = [ | |
{ | |
"inputs": [ | |
{ | |
"internalType": "string", | |
"name": "org", | |
"type": "string" | |
}, | |
{ | |
"internalType": "string", | |
"name": "dst", | |
"type": "string" | |
} | |
], | |
"name": "externalCompare", | |
"outputs": [ | |
{ | |
"internalType": "bool", | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"stateMutability": "pure", | |
"type": "function" | |
} | |
] | |
const byteCode = '608060405234801561001057600080fd5b5061039d806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80631ff5302214610030575b600080fd5b61004a6004803603810190610045919061013e565b610060565b604051610057919061020d565b60405180910390f35b600061006c8383610074565b905092915050565b60008160405160200161008791906101f6565b60405160208183030381529060405280519060200120836040516020016100ae91906101f6565b604051602081830303815290604052805190602001201415905092915050565b60006100e16100dc8461024d565b610228565b9050828152602081018484840111156100fd576100fc610347565b5b6101088482856102a0565b509392505050565b600082601f83011261012557610124610342565b5b81356101358482602086016100ce565b91505092915050565b6000806040838503121561015557610154610351565b5b600083013567ffffffffffffffff8111156101735761017261034c565b5b61017f85828601610110565b925050602083013567ffffffffffffffff8111156101a05761019f61034c565b5b6101ac85828601610110565b9150509250929050565b6101bf81610294565b82525050565b60006101d08261027e565b6101da8185610289565b93506101ea8185602086016102af565b80840191505092915050565b600061020282846101c5565b915081905092915050565b600060208201905061022260008301846101b6565b92915050565b6000610232610243565b905061023e82826102e2565b919050565b6000604051905090565b600067ffffffffffffffff82111561026857610267610313565b5b61027182610356565b9050602081019050919050565b600081519050919050565b600081905092915050565b60008115159050919050565b82818337600083830152505050565b60005b838110156102cd5780820151818401526020810190506102b2565b838111156102dc576000848401525b50505050565b6102eb82610356565b810181811067ffffffffffffffff8211171561030a57610309610313565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f830116905091905056fea2646970667358221220745385f4b28047d6825a2337d08da8b22f3ae1094e16c478cbab7ca0595ee89964736f6c63430008070033' | |
const deployerKeyring = caver.wallet.keyring.create(deployerAddress, deployerPrivateKey) | |
caver.wallet.add(deployerKeyring) | |
let contract = caver.contract.create(abi) | |
contract = await contract.deploy( | |
{ | |
from: deployerKeyring.address, | |
gas: 4000000, | |
}, | |
byteCode, | |
) | |
try { | |
let callResult = await contract.call('externalCompare', 'abc', 'bcd') | |
console.log(callResult) | |
} catch (err) { | |
console.log(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment