Example Usage
The below example code displays the usage of
customSigner
to remotely sign a transaction that was generated by Anchor Earn.For demonstration purposes, implementation of
customSigner
was done using Terra.js. For real usage customSigner
should be connected with a remote signing solution used by the integrator (e.g. Ledger Hardware Wallet, Custodian APIs).const anchorEarn = new AnchorEarn({
chain: CHAINS.TERRA,
network: NETWORKS.BOMBAY_12,
mnemonic:
'...',
});
// customSigner signs the generated unsigned tx
const customSigner = async (tx: Msg[]) => {
const account = new MnemonicKey({
mnemonic:
'...',
});
const wallet = new Wallet(
new LCDClient({
URL: 'https://bombay-lcd.terra.dev',
chainID: 'bombay-12',
}),
account,
);
return await wallet.createAndSignTx({
msgs: tx,
gasAdjustment: 2,
gasPrices: { uusd: 0.15 },
});
};
await anchorEarn.deposit({
amount: '0.01',
currency: DENOMS.UST,
log: (data) => {
console.log(data);
},
customSigner: customSigner,
});
The below example code displays the usage of
customBroadcaster
to remotely sign and broadcast a transaction that was generated by Anchor Earn.For demonstration purposes, implementation of
customBroadcaster
was done using Terra.js. For real usage customBroadcaster
should be connected with a remote signing solution used by the integrator (e.g. Web Wallet Extension).const anchorEarn = new AnchorEarn({
chain: CHAINS.TERRA,
network: NETWORKS.BOMBAY_12,
mnemonic:
'...',
});
// customBroadcaster signs and broadcasts the generated unsigned tx
const customBroadcaster = async (tx: Msg[]) => {
const lcd = new LCDClient({
URL: 'https://bombay-lcd.terra.dev',
chainID: 'bombay-12',
});
const wallet = new Wallet(
lcd,
new MnemonicKey({
mnemonic:
'...',
}),
);
const signedTx = await wallet.createAndSignTx({
msgs: tx,
gasAdjustment: 2,
gasPrices: { uusd: 0.15 },
});
return lcd.tx.broadcastSync(signedTx).then((result) => {
return result.txhash;
});
};
await anchorEarn.withdraw({
amount: '0.01',
currency: DENOMS.AUST,
log: (data) => {
console.log(data);
},
customBroadcaster: customBroadcaster
});
The below example code displays the usage of
loggable
to check on request progresses that were generated by Anchor Earn.const deposit = await anchorEarn.deposit({
amount: '...',
currency: DENOMS.UST,
log: (data) => {
console.log(data);
}
});
Last modified 1yr ago