Dynamically passing .contract-name to contract-call? function

Hello!

I am trying to call the transfer function in a SIP-010 token, but I need the .contract-name to be dynamic. I am passing it in a tuple and trying to use (get token share) as code below:

(define-private (transfer-to (share (tuple (recipient principal) (amount uint) (token <ft-trait>)))) (as-contract (contract-call? (get token share) transfer (get amount share) tx-sender (get recipient share) none)))

Why I am receiving the error: missing contract name for a call? What I am doing wrong?

Thanks!

1 Like

You can’t wrap the trait. If you pass the trait as a normal parameter, it should work. Something like this:
(define-private (transfer-to (share (tuple (recipient principal) (amount uint)) (token <ft-trait>))) (as-contract (contract-call? token transfer (get amount share) tx-sender (get recipient share) none)))

I don’t think there is a way to use traits in fold or map calls.

Warning, (as-contract (contract-call? token transfer...) can do anything with assets owned by the contract!

I don’t think there is a way to use traits in fold or map calls.

That is the main problem… I am trying to transfer assets to a list of principals. And to do that I am relying on a map call.

Probably I need to revisit the contract design.