Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to decode action from transaction? #68

Open
dev-dantealighieri opened this issue Jan 15, 2024 · 2 comments
Open

how to decode action from transaction? #68

dev-dantealighieri opened this issue Jan 15, 2024 · 2 comments

Comments

@dev-dantealighieri
Copy link

hi, I'm trying to decode Action from SignedTransaction object, I can decode memo and quantity, but unable to decode from and to into string objects.

here's what I do.

const transaction = Transaction.from(signedTransaction);
const action = Action.from(transaction.actions[0]);

const abi = await contractKit.load('eosin.token');
const decodedAction = action.decodeData(abi.abi) as any;

// from is Uint64, but I need address of account, e.g `garlicbutter`
const from = decodedAction?.from?.value; // ❌
const to = decodedAction?.to?.value.toString(); // ❌
const amount = decodedAction?.quantity?.value; // ✅
const memo = decodedAction?.memo;  // ✅
@aaroncox
Copy link
Member

Can you provide what the value of signedTransaction is so we can reproduce this?

@aaroncox
Copy link
Member

aaroncox commented Jan 15, 2024

Actually, maybe this helps:

const data = {
    account: 'eosio.token',
    authorization: [
        {
            actor: 'from',
            permission: 'active',
        },
    ],
    data: {
        from: 'foo',
        memo: '7783298',
        quantity: '1.0000 EOS',
        to: 'bar',
    },
    name: 'transfer',
}

const contract = await mockKit.load('eosio.token')
const action = Action.from(data, contract.abi)
const decodedAction = action.decodeData(contract.abi) as any

console.log(decodedAction)
console.log(String(decodedAction.from))
console.log(String(decodedAction.to))

That renders out both the from and to fields as strings. If you don't cast it to a string, it'll be a Name type value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants