javascript
import GraphQLClient from '@ocap/client';
import { fromSecretKey } from "@ocap/wallet";
import { toStakeAddress } from '@arcblock/did-util';
const privateKey = 'XXX';
const wallet = fromSecretKey(privateKey, 'eth');
console.log(wallet.address);
const client = new GraphQLClient("https://beta.abtnetwork.io/api/");
await client.getContext();
const token = {
address: 'z35n6UoHSi9MED4uaQy6ozFgKPaZj2UKrurBG',
value: '1'
};
const stakeAddress = toStakeAddress( wallet.address, wallet.address);
console.log(stakeAddress);
// client.getContext().then(() => {
// client.stake({
// tokens: [{
// address: 'z35n6UoHSi9MED4uaQy6ozFgKPaZj2UKrurBG',
// value: '1'
// }],
// to: wallet.address,
// locked: false,
// message: 'stake-test',
// wallet
// }).then(([hash, address]) =>{
// console.log(hash, address);
// });
// });
// const revokeStakeResult = await client.revokeStake({
// tokens:[token],
// from: stakeAddress,
// wallet
// });
// console.log(revokeStakeResult);
// const claimStakeResult = await client.claimStake({
// from: stakeAddress,
// evidence:revokeStakeResult,
// wallet
// });
// console.log(claimStakeResult);
const result = await client.slashStake({
tokens: [token],
from: stakeAddress,
reason: 'slash-stake-test',
wallet
});
console.log(result);
// const result = await client.listStakes();
// console.log(result);
Error: GraphQLError: You are not allowed to slash from this stake
at NativeGraphqlClient._doRequest (/Users/hiker/demo/chain/node_modules/.pnpm/@arcblock+sdk-util@0.34.3/node_modules/@arcblock/sdk-util/lib/index.js:275:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/hiker/demo/chain/node_modules/.pnpm/@ocap+client@1.18.124/node_modules/@ocap/client/lib/extension.js:398:28 {
errors: [
{
code: 'INVALID_TX',
message: 'You are not allowed to slash from this stake',
locations: [ { line: 2, column: 3 } ],
stack: [],
path: [ 'sendTx' ]
}
],
txHash: 'F9A3E38DFE13A1B6F0BF9BAD6343DBB19244FA53F376AE783979DCCC0381D302'
}
1 reply
我刚刚注意到了 stake的时候可以设置slashers地址,我再试试