codestates / DIDNOW

퍼블릭 블록체인 네트워크를 이용한 DID 기반 인증서 관리 플랫폼
https://didnow.cf
10 stars 8 forks source link

CaverJS 수수료 위임 찾아보기 #30

Closed donggni0712 closed 2 years ago

donggni0712 commented 2 years ago
  1. [x] caverJS 함수 실행 후 트랜잭션 수수료 위임 테스트
donggni0712 commented 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()