Skip to content

Instantly share code, notes, and snippets.

@SuperstrongBE
Created November 5, 2022 00:07
Show Gist options
  • Save SuperstrongBE/7c7b381478a12afa018c5f15e3d938f9 to your computer and use it in GitHub Desktop.
Save SuperstrongBE/7c7b381478a12afa018c5f15e3d938f9 to your computer and use it in GitHub Desktop.
import { Api, JsonRpc, JsSignatureProvider } from "@proton/js";
// THOSE ENDPOINTS ARE TESTNET
// BE SURE TO TEST THIS SCRIPT WITH A TESTNET ACCOUNT
const EPS = [
"https://testnet.brotonbp.com",
"https://api-protontest.saltant.io",
"https://api.testnet.protongb.com",
"https://testnet-api.protongroup.info",
"https://test.proton.kiwi",
"https://bptestnet.xprasia.com",
];
export class GetRewardTes {
private rpc: JsonRpc = new JsonRpc(EPS);
/*
## NEEDED ONLY IF YOU WANT TO CALL SMART CONTRACT FROM BACKEND, NEVER USE ON FRONT END !!!!!
private sign: JsSignatureProvider = new JsSignatureProvider([
"... proton_account_private_key...",
]);
*/
private api = new Api({ rpc: this.rpc, signatureProvider: this.sign });
// PUBLIC FETCH OF A TABLE NAMED STAKERS SO NOT SIGN IS NEEDED
async fetchStakes() {
const rows = await this.api.rpc.get_table_rows({
code: "snipstake",
table: "stakers",
scope: "crotte",
limit: 2000,
//reverse:true
});
return rows;
}
// CALLING A SMART CONTRACT IN THE NAME OF CROTTE REQUIRE SIGN
// (FROM THE WEB AUTH IF IS FRONTEND OR WITH THE SIGN STUFF On TOP OF THE FILE)
async pushStake() {
const action = {
account: "snipstake",
name: "transfer",
authorization: [{ actor: "crotte", permission: "active" }],
data: {
from: "crotte",
to: account.actor,
amount: Math.floor(Math.random() * 100000000)+10000,
}
};
// YOU CAN ALSO FIND THE TRANSACT FUNCTION IN THE
// PROTON WEB SDK (FOR FRONT END USER WALLET IINTERACTION)
return await this.api.transact(
{
actions: [action],
},
{
blocksBehind: 3,
expireSeconds: 30,
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment