Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Native Parameters

Icon LinkNative Parameter Types

Below you can find examples of how to convert between common native Sway program input and output types:

Icon LinkAddress

Icon LinkAddressInput

To pass an Address as an input parameter to a Sway program, you can define the input as shown below:

// #import { Address };
const address = Address.fromRandom();
const addressInput = { bits: address.toB256() };

Icon LinkAddressOutput

For a Sway program that returns an Address type, you can convert the returned value to an Address type in fuels as shown below:

// #import { Address };
const addressOutput = callResponse.value;
const addressFromOutput: Address = Address.fromB256(addressOutput.bits);

Icon LinkContractId

Icon LinkContractIdInput

To pass a ContractId as an input parameter to a Sway program, you can define the input as shown below:

const contractId = '0x7296ff960b5eb86b5f79aa587d7ebe1bae147c7cac046a16d062fbd7f3a753ec';
const contractIdInput = { bits: contractId.toString() };

Icon LinkContractIdOutput

For a Sway program that returns a ContractId type, you can convert the returned value to a string as shown below:

const contractIdOutput = callResponse.value;
const contractIdFromOutput: string = contractIdOutput.bits;

Icon LinkIdentity

Icon LinkIdentityInput

To pass an Identity as an input parameter to a Sway program, you can define the input as shown below:

For an address:

// #import { Address };
const address = Address.fromRandom();
const addressInput = { bits: address.toB256() };
const addressIdentityInput = { Address: addressInput };

For a contract:

const contractId = '0x7296ff960b5eb86b5f79aa587d7ebe1bae147c7cac046a16d062fbd7f3a753ec';
const contractIdInput = { bits: contractId.toString() };
const contractIdentityInput = { ContractId: contractIdInput };

Icon LinkIdentityOutput

For a Sway program that returns an Identity type, you can convert the returned value to an Address or string as shown below:

For an address:

// #import { Address };
const identityFromOutput1 = callResponse1.value;
const addressStringFromOutput = identityFromOutput1.Address.bits;
const addressFromOutput: Address = Address.fromB256(addressStringFromOutput);

For a contract:

const identityFromOutput2 = callResponse2.value;
const contractIdFromOutput: string = identityFromOutput2.ContractId.bits;

Icon LinkAssetId

Icon LinkAssetIdInput

To pass an AssetId as an input parameter to a Sway program, you can define the input as shown below:

const assetId = '0x0cfabde7bbe58d253cf3103d8f55d26987b3dc4691205b9299ac6826c613a2e2';
const assetIdInput = { bits: assetId };

Icon LinkAssetIdOutput

For a Sway program that returns an AssetId type, you can convert the returned value to a string as shown below:

const assetIdOutput = callResponse.value;
const assetIdFromOutput: string = assetIdOutput.bits;