contractimport macro generates type-safe client code for calling external contracts.
Using contractimport
Thecontractimport macro generates a client from a compiled WASM file:
What contractimport Generates
The macro generates several types:Client- Type-safe client for calling the contractWASM- The compiled WASM bytecode (as&[u8])- Function-specific types and traits
Calling External Contracts
Basic Cross-Contract Call
Calling Token Contracts
The SDK provides built-in support for token contracts:Importing Local Contract Definitions
You can also call contracts defined in the same workspace:Registering Contracts in Tests
Register with Generated ID
Register at Specific ID
Re-registering Contracts
You can replace a contract’s code at an existing ID:Authentication and Authorization
Cross-contract calls respect the authentication context:Error Handling
Cross-contract calls panic if the external contract:- Doesn’t exist at the given address
- Panics or returns an error
- Has an incompatible interface