Unable to transfer Aions from contract to another account

I’m trying to transfer Aions from my contract to another account using the following function by using the function call at transferAion in https://docs.aion.network/docs/transfer-aion

 public static void checkHours(int hr1, int hr2, byte[] value)
    {

        user1.setHrs(hr1);
        user2.setHrs(hr2);
        if(hr1>hr2)
        {
            to = user1.getAdd();
        }
        else
        {
            to = user2.getAdd();
        }
        //onlyOwner();
        Blockchain.call(to, new BigInteger(value), new byte[0], Blockchain.getRemainingEnergy());
    }

All transactions are successful but the value is not being transferred to the appropriate account.
I have used Maven through CLI to deploy and sign the transaction and also tried it through the frontend using web3
For maven I’m using:

mvn aion4j:contract-txn -Dcontract=0xA0CB3a6445B9036D30E955c2496E4c6687643984C0acBE653CD6fe20649338C9 -Dmethod=checkHours -Dargs="-I 3 -I 4 -B[] 2" -Premote

And for web3 I used:

let data = web3.avm.contract.method('checkHours').inputs(
        [
            'Int',
            'Int',
            'Byte[]'
        ], [
            '7',
            '5',
            value
        ]).encode();

to create the Transaction object where the variable value is defined as:

var value = new Uint8Array(1);
value = [2];

Is the error due to the contract logic or the calling statements?

Hi, I suspect the problem is that AVM is using the smallest unit of Aion for values, which is nAmp.
1 Aion = 10^18 nAmp, that’s why 2 nAmp is barely noticeable. That being said, if you want to transfer 2 Aion in Java contract, the value should be 2*10^18.

If you are using web3.js, instead of using unit8Array, I would suggest you to define an array that is 32 bytes (BigInteger Size) and specify it to be in Big Endian order.

For example:

 var namp = new BN("1000000000000000000");
 var amount = new BN("2");
let amountInNamp = namp.mul(amount);
let value = amountInNamp.toArray('be',32);

Let me know if this works for you!

3 Likes

Yeah this worked! Thanks a lot!