Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delegateAmount() #1

Open
Kreeptonium opened this issue Mar 22, 2022 · 1 comment
Open

delegateAmount() #1

Kreeptonium opened this issue Mar 22, 2022 · 1 comment

Comments

@Kreeptonium
Copy link

I have tried using this library to build delegation. As per library it calls buyVoucher function internally.
But when I tried executing the validatorShare.addDelegation('xxx','xxx') then it didn't call the buyVoucher function. Instead it excuted the code & generated the hash below:
hash = 0xb2b224ccab3b600eedf775790ae746c4d526648e35ab094a75cd8dd883684894
I did delegation using metamask so the result was like below:
Approve(Hash): 0xca485e5b31a8b7cb0f087805114124167a006681ee788d7176122487122a123b
buyVoucher(Hash): 0x2c6dc671a522744216e43b7380c9bfea73337ddf7a4fc10f81eac99885e2a310


Below is the code I have built to use addDelegation() function

import { Web3ClientPlugin } from "@maticnetwork/maticjs-ethers";
import { ABIManager, use } from "@maticnetwork/maticjs";
import { StakingClient } from "@maticnetwork/maticjs-staking";

import { providers, Wallet } from "ethers";
use(Web3ClientPlugin);

export const main = async ():Promise => {

let stakingClient = new StakingClient();

const VALIDATOR_ADDRESS='0xf903ba9e006193c1527bfbe65fe2123704ea3f99';

const from_Parent ='0xA70db639f26d907B7744e72c44e9f0562f6fb6Ce';
const from_Child ='0xd8C57108d94d5c528cE40Cc2d0cF5FcaB035614F';

try {

const parentProvider = new providers.JsonRpcProvider('https://goerli.infura.io/v3/8ff9246da3ee488487ee9bdf43e22d64');
const childProvider = new providers.JsonRpcProvider('https://polygon-mumbai.infura.io/v3/8ff9246da3ee488487ee9bdf43e22d64');

const PrivateKey_Parent='0x508516767f6XXXX32f4XXXXa1e5401145a1585XXXXc565df7d28fa0cf9fee1c3';
const PrivateKey_Child='0x9XXXXXX2bc7a0e50a24e5943d8776b2d86fdb06c4f6caXXXXXX5d3172b2928d5';

await stakingClient.init({

network: 'testnet',
version: 'mumbai',
parent: {
  
    provider: new Wallet(PrivateKey_Parent, parentProvider),
    defaultConfig: {
        from:from_Parent
    }
},
child: {
    provider: new Wallet(PrivateKey_Child, childProvider),
    defaultConfig: {
        //from:PrivateKey_Parent
        from:from_Child
    }
}

})

const abiManager = new ABIManager('testnet','mumbai');
await abiManager.init();

const validatorShare = stakingClient.validatorShare(VALIDATOR_ADDRESS);

var result=await validatorShare.delegateAmount('1000000000000000000','950000000000000000');

let hash = await result.getTransactionHash();
console.log("Hash: ",hash);
} catch (error) {

console.log("Error: ",error);

}
}

main().then(()=>console.log("Success"))
.catch((error)=>console.log("Error: ", error))


It will be great help if you could provide solution on the above issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@Kreeptonium and others