Coinbase currency transfer

Hello. I have tried following the docs on Coinbase send money, request, and transfer funds, but the JavaScript does not work. What is the JavaScript code that can transfer an amount (eg: 0.055, 0.1,2,etc.) of a currency (BTC, LTC, ETH, etc.) to another specific user? Please let me know.

Hi @mkiefer ! Welcome to the forum! Thank you for taking an interest in trying out Coinbase APIs. Can you share more details regarding your concern? It would be helpful if you can provide an example of your code, and what response you are getting back from our API. This will help us to further investigate any issues that you may be experiencing. Thank you so much!

2 Likes

Hello. I have the file of my code attached. The response is that nothing is happening. There is no error, but there is no currency transfer. The code is below.

const coinbase = require(‘coinbase’);
logErrorSchema = require(‘…/models/logErrors’);

module.exports = {
getClient: async (req, res) => {
try {

        const Client = require('coinbase').Client;
        const client = new Client({ 'accessToken': accessToken, 'refreshToken': refreshToken });

        res.send(client);
    } catch (error) {
        res.status(500).send(error);
    }
},
getAccount: async (req, res) => {
    try {
        //wallet:accounts:read,wallet:addresses:read,wallet:buys:read
        const data = req.body;
        // console.log(data);
        const client = new coinbase.Client({
                                            'accessToken': data.accessToken, 
                                            'refreshToken': data.refreshToken,
                                             strictSSL: false
                                            });

        let address = null;                               
        let amount = null;
        let currency = null; 


        client.getAccount('primary', function (err, account) {
            // console.log('account', account);
            // console.log('account-err', err);
          
            account.createAddress(null, function (err, addr) {
                //console.log(err);
                address = addr;
                // console.log('err - ', err);
                // console.log('add - ', address);

                if (account && parseFloat(account.balance > 0)) {
                    account.sendMoney({
                        'to': address,
                        'amount': amount,
                        'currency': currency
                    }, function (err, tx) {

                      //  console.log('ERR', err);
                       // console.log('TX', tx);
                        // return res.send({ data: 'ok' });
                    });
                }
            });

            
            
        });
      // return res.send({ data: 'no data'});
    } catch (error) {
        console.log(error.response);
        const logErrorModel = {
            controller: 'coinbaseController',
            error: error,
            model: req.body,
        };
        const logE = new logErrorSchema(logErrorModel);
        logE.save();
        return res.status(500).send(error);
    }
},
setFunds: async (req, res) => {
    try {
        const Client = require('coinbase').Client;

        const client = new Client({
            'apiKey': '',
            'apiSecret': '',
            'version': 'YYYY-MM-DD',
            strictSSL: false
        });

        let address = null; //'3KTwyFhct2o9rfD6KRmXatA4ZGTNkTkayT';                               
        let amount = null;
        let currency = null; 

        client.getAccount('primary', function (err, account) {
            account.createAddress(function (err, addr) {
                console.log(err);
                address = addr;
            });
        });

        console.log(address, 'address');

        client.getAccount('primary', function (err, account) {
            account.sendMoney({
                'to': address,
                'amount': amount,
                'currency': currency
            }, function (err, tx) {

                console.log('ERR', tx);
                console.log('TX', tx);
            });
        });

    } catch (error) {
        console.log(error.response);
        const logErrorModel = {
            controller: 'coinbaseController',
            error: error,
            model: req.body,
        };
        const logE = new logErrorSchema(logErrorModel);
        logE.save();
        res.status(500).send(error);
    }
},
sending: (req, res) => {
    try {
        //wallet:accounts:read,wallet:addresses:read,wallet:buys:read
        const data = req.body;
        // console.log(data);
        // Token will be important for minting NFTs uniquely
        const client = new coinbase.Client({
            'accessToken': data.accessToken,
            'refreshToken': data.refreshToken,
            strictSSL: false
        });

        client.getAccount('primary', function (err, account) {

            var args = {
                'to': address,
                'amount': '0.00001',
                'currency': 'LTC',
                'description': ' A sample transaction for you'
            };
            account.sendMoney(args, function (err, txn) {
                console.log('my txn id is: ' + err);
                return res.send({ data: txn });
            });
        });
        // return res.send({ data: 'no data'});
    } catch (error) {
        console.log(error.response);
        const logErrorModel = {
            controller: 'coinbaseController',
            error: error,
            model: req.body,
        };
        const logE = new logErrorSchema(logErrorModel);
        logE.save();
        return res.status(500).send(error);
    }
},
requesting: async (req, res) => {
    try {
        // following coinbase API docs on requesting an amount of currency via na email address for a transaction request
        const Client = require('coinbase').Client;

        const client = new Client({
            'apiKey': '',
            'apiSecret': '',
            'version': 'YYYY-MM-DD',
            strictSSL: false
        });

        let address = null; //'3KTwyFhct2o9rfD6KRmXatA4ZGTNkTkayT';                             
        let amount = null;
        let currency = null; 

        client.getAccount('primary', function (err, account) {
            account.createAddress(function (err, addr) {
                console.log(err);
                address = addr;
            });
        });

        console.log(address, 'address');

        client.getAccount('primary', function (err, account) {
            account.requestMoney({
                'to': 'mkiefer@cryptoramaglobal.com',
                'amount': amount,
                'currency': currency
            }, function (err, tx) {

                console.log('ERR', tx);
                console.log('TX', tx);
            });
        });

    } catch (error) {
        console.log(error.response);
        const logErrorModel = {
            controller: 'coinbaseController',
            error: error,
            model: req.body,
        };
        const logE = new logErrorSchema(logErrorModel);
        logE.save();
        res.status(500).send(error);
    }
},
        
transferring: async (req, res) => {
    try {
        // following the coinbase API docs for transferring a currency amount from wallet to wallet
        const Client = require('coinbase').Client;

        const client = new Client({
            'apiKey': '',
            'apiSecret': '',
            'version': 'YYYY-MM-DD',
            strictSSL: false
        });

        let address = null; //'3KTwyFhct2o9rfD6KRmXatA4ZGTNkTkayT';                              
        let amount = null;
        let currency = null; 

        client.getAccount('primary', function (err, account) {
            account.createAddress(function (err, addr) {
                console.log(err);
                address = addr;
            });
        });

        console.log(address, 'address');

        client.getAccount('primary', function (err, account) {
            account.transferMoney({
                'to': address,
                'amount': amount,
                'currency': currency
            }, function (err, tx) {

                console.log('ERR', tx);
                console.log('TX', tx);
            });
        });

    } catch (error) {
        console.log(error.response);
        const logErrorModel = {
            controller: 'coinbaseController',
            error: error,
            model: req.body,
        };
        const logE = new logErrorSchema(logErrorModel);
        logE.save();
        res.status(500).send(error);
    }
},

};