Agents need Bitcoin too.
CBBTCAgentPlugin
is a Node.js library for interacting with the cbBTC (Coinbase Bitcoin) token on the Base blockchain. It provides methods for checking balances, transferring tokens, and approving token spending.
- Check cbBTC token balance for any address
- Transfer cbBTC tokens
- Approve token spending for a specific address
- Robust error handling
- Gas estimation and transaction management
- Node.js (v16.0.0 or later)
- An Ethereum wallet with private key
- Base blockchain RPC URL
- Clone the repository:
git clone https://github.com/cmpgfb/cbbtc-agent-plugin.git
cd cbbtc-agent-plugin
- Install dependencies:
npm install
- Create a
.env
file:
cp .env.example .env
- Fill in your environment variables in the
.env
file.
const CBBTCAgentPlugin = require('./src/CBBTCAgentPlugin');
require('dotenv').config();
async function main() {
try {
// Initialize the plugin
const plugin = new CBBTCAgentPlugin(
process.env.PRIVATE_KEY,
process.env.BASE_RPC_URL
);
// Check balance
const balance = await plugin.checkBalance('0x1234...');
console.log('Balance:', balance);
// Transfer tokens
const txHash = await plugin.transferCbBTC(
'0x5678...',
'0.1' // Amount in cbBTC
);
console.log('Transfer TX Hash:', txHash);
// Approve spending
const approvalHash = await plugin.approveSpender(
'0x9012...',
'1.0' // Amount in cbBTC
);
console.log('Approval TX Hash:', approvalHash);
} catch (error) {
console.error('Error:', error.message);
}
}
main();
PRIVATE_KEY
: Your Ethereum wallet's private keyBASE_RPC_URL
: RPC endpoint for the Base blockchain
The plugin provides detailed error messages for:
- Invalid addresses
- Invalid token amounts
- Network or transaction errors
- Never expose your private key
- Use environment variables for sensitive information
- Keep your
.env
file private and out of version control
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Christopher Perceptions - [email protected]
Project Link: https://github.com/cmpgfb/cbbtc-agent-plugin
Built during NoCodeHacking 2024