Skip to content

Commit ccf398c

Browse files
Merge pull request #6826 from BitGo/feat/COIN-4135-allow-token-approval-for-bsc
feat: allow bsc to enable token for send many
2 parents cdcba42 + 69b5d1e commit ccf398c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Approve an ERC20 token for use with a batcher contract at BitGo.
3+
*
4+
* Copyright 2023, BitGo, Inc. All Rights Reserved.
5+
*/
6+
import { BitGoAPI } from '@bitgo/sdk-api';
7+
import { Tbsc } from '@bitgo/sdk-coin-bsc';
8+
require('dotenv').config({ path: '../../.env' });
9+
10+
const bitgo = new BitGoAPI({
11+
accessToken: process.env.TESTNET_ACCESS_TOKEN,
12+
env: 'staging',
13+
});
14+
15+
const coin = 'tbsc';
16+
bitgo.register(coin, Tbsc.createInstance);
17+
18+
const walletId = process.env.TESTNET_BSC_WALLET_ID;
19+
const walletPassphrase = process.env.TESTNET_BSC_WALLET_PASSPHRASE;
20+
const tokenName = 'tbsc:busd'; // Replace with the token you want to approve
21+
22+
async function main() {
23+
if (!walletId) {
24+
throw new Error('Please set TESTNET_BSC_WALLET_ID environment variable');
25+
}
26+
if (!walletPassphrase) {
27+
throw new Error('Please set TESTNET_BSC_WALLET_PASSPHRASE environment variable');
28+
}
29+
30+
const walletInstance = await bitgo.coin(coin).wallets().get({ id: walletId });
31+
32+
console.log('Wallet ID:', walletInstance.id());
33+
console.log('Current Receive Address:', walletInstance.receiveAddress());
34+
35+
console.log(`Approving token ${tokenName} for use with batcher contract...`);
36+
37+
try {
38+
const approvalTransaction = await walletInstance.sendMany({ type: 'tokenApproval', walletPassphrase, tokenName });
39+
40+
console.log('Token Approval Transaction:', JSON.stringify(approvalTransaction, null, 4));
41+
console.log('Transaction ID:', approvalTransaction.txid);
42+
console.log('Status:', approvalTransaction.status);
43+
} catch (e) {
44+
console.error('Error approving token:', e.message);
45+
if (e.stack) {
46+
console.error(e.stack);
47+
}
48+
}
49+
}
50+
51+
main().catch((e) => console.error(e));

modules/sdk-coin-bsc/src/bsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class Bsc extends AbstractEthLikeNewCoins {
7575
!txParams?.recipients &&
7676
!(
7777
txParams.prebuildTx?.consolidateId ||
78-
(txParams.type && ['acceleration', 'fillNonce', 'transferToken'].includes(txParams.type))
78+
(txParams.type && ['acceleration', 'fillNonce', 'transferToken', 'tokenApproval'].includes(txParams.type))
7979
)
8080
) {
8181
throw new Error(`missing txParams`);

0 commit comments

Comments
 (0)