Skip to content

how to send records similar to dfx #86

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

Open
aknowel opened this issue Nov 8, 2022 · 1 comment
Open

how to send records similar to dfx #86

aknowel opened this issue Nov 8, 2022 · 1 comment

Comments

@aknowel
Copy link

aknowel commented Nov 8, 2022

Hi I have a problem using ic-py library.

I would like to mint canister tokens and send request similar to

dfx canister --network ${NETWORK} call ${CANISTER_ADDRESS} transfer '(record {
  memo = 0 : nat64;
  amount = record { e8s = 100 : nat64 };
  fee = record { e8s = 0 : nat64 };
  from_subaccount = null;
  to = '${TOKENS_TRANSFER_ACCOUNT_ID_BYTES}' : vec nat8;
  created_at_time = null;
})'

But I am not sure how to use ic-py params to fulfill my needs. It would be ideal to do something similar to

params = {
	"memo": 0,
	"amount": { "e8s": 100 },
	"fee": { "e8s": 0 },
	"from_subaccount": None,
	"to": ["${TOKENS_TRANSFER_ACCOUNT_ID_BYTES}"],
	"created_at_time": None,
}
result = agent.update_raw("${CANISTER_ADDRESS}", "transfer", encode(params))
print(result)

If you have any idea what approach could I take, please share.
Library documentation has only few simple examples and so I couldn't get it done yet

@Myse1f
Copy link
Contributor

Myse1f commented Nov 11, 2022

You need to provide the type structure, like

# transfer 100 token to blackhole address `aaaaa-aa`
params = [
	{'type': Types.Principal, 'value': 'aaaaa-aa'},
	{'type': Types.Nat, 'value': 10000000000}
]
result = agent.update_raw("gvbup-jyaaa-aaaah-qcdwa-cai", "transfer", encode(params))

For ur code, set params like this:

params = [{
    'type': Types.Record({
          "memo": Types.Nat64,
          "amont": Types.Record({"e8s": Types.Nat64}),
          ......
     }), 
     'value': {
	"memo": 0,
	"amount": { "e8s": 100 },
	"fee": { "e8s": 0 },
	"from_subaccount": None,
	"to": ["${TOKENS_TRANSFER_ACCOUNT_ID_BYTES}"],
	"created_at_time": [], # None is empty array
}
}]

Better to use Canister to parse the did file. Pls refer to here

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