As title says, working on tutorial 11 (advanced account updates), and having a hard time getting an account to send tokens from itself to another account.
Have the following code in the "TokenUser" account:
@method sendMyTokens(
amount: UInt64,
destination: PublicKey
) {
const myTokenInstance = new MyToken(TokenUser.myTokenPublicKey);
const tokenUserContract = new TokenUser(
this.address,
myTokenInstance.token.id
);
tokenUserContract.subtractTokens(amount);
const subtractTokens = tokenUserContract.self;
myTokenInstance.approveTransfer(subtractTokens, destination, amount);
}
@method subtractTokens(amount: UInt64) {
// TODO this could let anyone subtract balance, how to do this pattern correctly so that balance is only subtracted if the "other half" of the intended behavior performed? (in this case, tokens being sent elsewhere)
this.balance.subInPlace(amount);
}
And the following code in the MyToken Account:
@method approveTransfer(
transferUpdate: AccountUpdate,
to: PublicKey,
amount: UInt64
) {
// TODO assert not approvign anything else
this.approve(transferUpdate);
// see if balance change cancels the amount sent
let balanceChange = Int64.fromObject(transferUpdate.body.balanceChange);
balanceChange.assertEquals(Int64.from(amount).neg());
// add same amount of tokens to the receiving address
this.token.mint({ address: to, amount });
}
Yielding the following error:
Error: [[["Token_owner_not_caller"]],[["Cancelled"]],[["Cancelled"]],[["Cancelled"]],[["Cancelled"]]]
Code found here: https://github.com/o1-labs/docs2/tree/tutorial-11/examples/zkapps/11-advanced-account-updates
Thanks, any ideas towards fixing appreciated
GitHub
Docs website for the Mina Protocol. Contribute to o1-labs/docs2 development by creating an account on GitHub.