Closed donggni0712 closed 2 years ago
아래와 같은 느낌으로 작성하면 되는 듯.
const fs = require('fs')
const Caver = require('caver-js')
const caver = new Caver('https://api.baobab.klaytn.net:8651/')
const dotenv = require("dotenv");
dotenv.config();
const DIDContractABI = require('./DIDCONTRACT_ABI.json');
const DIDContractAddress = "0x67f136D4F35C981C62c3EEA9c127f0a9d8De8E95";
async function testFunction() {
// Decrypt keystore
const keyring = caver.wallet.keyring.createFromPrivateKey(
process.env.PRIVATEKEY
);
console.log(keyring)
// Add to caver.wallet
caver.wallet.add(keyring)
const DIDContract = new caver.contract(DIDContractABI, DIDContractAddress);
// Create value transfer transaction
const executionTx = await DIDContract.sign({
from: keyring.address,
feeDelegation: true,
feePayer: keyring.address,
feeRatio: 50, // Without feeRatio, `send` will use FeeDelegatedSmartContractExecution
gas: 1000000,
}, 'addService', 'did:klay:7423de10c75b1d4d1f30a4d81386e3aaf22584f9', 'testID2', 'testPubKey')
console.log(`Deployer signed transaction: `)
console.log(executionTx)
//const signed = await caver.wallet.sign(keyring.address, executionTx)
const signed = await caver.wallet.signAsFeePayer(keyring.address, executionTx)
const receipt = await caver.rpc.klay.sendRawTransaction(signed)
console.log(receipt)
}
testFunction()