본문 바로가기

프로그래밍

kaikas API 지갑 연동

반응형

 

 

바닐라 JS로 카이카스 지갑 연동 및 트랜잭션

let accounts;

klaytn.on('accountsChanged', function(acc) {
    accounts = acc;
    if ( accounts && accounts.length > 0 )
    {
        // alert(accounts);
        // display_button(true);
    } else {
        // display_button(false);
    }
})

const kaikas_connect = async () =>{

    if (typeof window.klaytn !== 'undefined') {
        const provider = window['klaytn'];
        // Kaikas user detected. You can now use the provider.
        try {
            const accounts = await klaytn.enable();
          } catch (error) {
            console.error(error)
          }
      }

};

const send = async () =>{
    
    const addr = '0x6F8bA1EEDa3FEA14162864F763cF97E7E02fE30F';
    const price = 50;

    const gas = 80000000;
    caver.klay.sendTransaction({
        from: klaytn.selectedAddress,
        to: addr,
        value: caver.utils.toPeb(price.toString(), 'KLAY'),
        gas: gas
    })
    .then(function(receipt){
    });

};

 

반응형