Error in transfer call.why?

import { Provider, Wallet } from 'fuels';

const test = async () => {
    const provider = new Provider("");
    const senderWallet = Wallet.fromPrivateKey('0xdbec40d37e64977120a23dc1924fdfdd5f12e1f2221ae5363173937c5d63aef6', provider);
    const destinationWallet = Wallet.generate();
    const amountToTransfer = 500;
    const assetId = '0x0000000000000000000000000000000000000000000000000000000000000000';

    try {
        const response = await senderWallet.transfer(
        await response.wait();
        // Retrieve balances
        const receiverBalance = await destinationWallet.getBalance(assetId);
    } catch (e) {



version :0.52.0

Error: Unknown type “MessageCoin”: {“response”:{“data”:null,“errors”:[{“message”:“Unknown type "MessageCoin"”,“locations”:[{“line”:23,“column”:1}]},{“message”:“Unknown field "txCreatedIdx" on type "Coin".”,“locations”:[{“line”:20,“column”:3}]},{“message”:“Unknown field "coinsToSpend" on type "Query". Did you mean "resourcesToSpend"?”,“locations”:[{“line”:2,“column”:3}]}],“status”:200,“headers”:{}},“request”:{“query”:“query getCoinsToSpend($owner: Address!, $queryPerAsset: [SpendQueryElementInput!]!, $excludedIds: ExcludeInput) {\n coinsToSpend(\n owner: $owner\n queryPerAsset: $queryPerAsset\n excludedIds: $excludedIds\n ) {\n …coinFragment\n …messageCoinFragment\n }\n}\n\nfragment coinFragment on Coin {\n __typename\n utxoId\n owner\n amount\n assetId\n maturity\n blockCreated\n txCreatedIdx\n}\n\nfragment messageCoinFragment on MessageCoin {\n __typename\n sender\n recipient\n nonce\n amount\n assetId\n daHeight\n}”,“variables”:{“owner”:“0x7e40d1abdf7850b3d95c7a22e66f02f12964f799426d15cdb9291ce118b96b67”,“queryPerAsset”:[{“assetId”:“0x0000000000000000000000000000000000000000000000000000000000000000”,“amount”:“501”}],“excludedIds”:{“messages”:,“utxos”:}}}}

Hi @zhoud, that version of the TS SDK is not supported on beta-3, please could you try downgrading to v0.31.0, rerunning and reporting the result, thanks!

FetchError: request to failed, reason: connect ECONNREFUSED

Are you still connecting to the beta-3 url, that looks like you are trying to connect to a local testnet?

yes,still connecting to the beta-3 url

Would you be able to share the repository? Or more of the code?

So I can see that the transfer() made on the beta-3 network is succeeding. However the FetchError is being thrown on line 22 by the getBalance() call on the receiver wallet.

By default, the provider url is set to So when generating the destination wallet, it is using the default provider url. In order to connect the destination wallet to the beta-3 network, call:

await destinationWallet.provider.connect("");

before attempting to call getBalance() on the destination wallet, and you should be able to successfully log the receiver balance.

Alternatively, you could also pass the provider in when generating the destination wallet:

const destinationWallet = Wallet.generate({ provider });

Let me know if this doesn’t resolve it for you :slight_smile:

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.