types APIs
- SimpleOptions
- RootState
- User
- ChainType
- FeedbackCategoryAPI
- FeedbackStatusAPI
- FeedbackUserProfileAPI
- NavItems
- SingleNavItem
- NonNullableChildrenDeep
- SingleArticle
- ColumnType
- DataType
- Hub
- PluginConfig
- RawEventMessage
- DualStakingInfo
- StakingInfo
- SyrupInfo
- CommonStakingInfo
- LairInfo
- StakingBasic
- DualStakingBasic
- SyrupBasic
- Questionnaire
- TaskStatuses
- LoginPayload
- SignupPayload
- MutationType
- ProteinSize
- Config
- Themes
- defaults
- CoordinateSpaceInitial
- Background
- Metric
- Metadata
- TManageValue
- Domain
- Organization
- OrganizationTag
- Scan
- ScanSchema
- Query
- SavedSearch
- Role
- ScanTask
- Vulnerability
- GenericObject
- Annotation
- AnnotationList
- VideoAnnotation
- IconName
- IllustrationName
- INotification
- BottomTabScreens
- KYCScreens
- CCVPScreens
- LoginScreens
- PreAuthScreens
- SignUpScreens
- TFAScreens
- PNVScreens
- ProfileScreens
- SecurityScreens
- SMTYFScreens
- WalletScreens
- WithdrawalScreens
- StackNavigationProps
- Coin
- Country
- TransactionStatus
- SetApiActionPayloadInterface
- LoadingStateInterface
- MessageStateInterface
- UiOptionType
- ApiDiffInterface
- ApiStateInterface
- Account
- NFT
- NFTDetails
- AlertType
- DefaultTemplateOptions
- ProviderProps
- AlertTimer
- AlertInstance
- AlertOptions
- TemplateAlertOptions
- AlertContainerFactory
- ChainBase
- ChainNetwork
- WalletId
- ProposalType
- ChainEventNotification
- WebsocketMessageNames
- WebsocketNamespaces
- NotificationCategories
- InviteCodeAttributes
- IPostNotificationData
- ChainCategoryType
- Screens
- NavigationProperty
- IP
- Maybe
- Tuple
- ChainProperties
- ApiPromise
- ApiAction
- BlueprintOptions
- ContractQuery
- ContractOptions
- ContractTx
- KeyringPair
- ContractDryRunParams
- InstantiateData
- SubmittableExtrinsic
- DbState
- OnInstantiateSuccess$Code
- OnInstantiateSuccess$Hash
- InstantiateState
- ApiState
- OrFalsy
- Bytes
- AbiParam
- Registry
- Weight
- SubmittableResult
- Hash
- CodeBundleDocument
- MyCodeBundles
- ContractDocument
- MyContracts
- Database
- DbStatistics
- UserDocument
- QueuedTxOptions
- TransactionsState
- DropdownOption
- DropdownProps
- ValidFormField
- SetState
- BN
- CallResult
- ContractPromise
- RegistryError
- Abi
- TypeDef
- Validation
- FileState
- UseWeight
- ArgComponentProps
- TypeDefInfo
- UseMetadata
- AbiMessage
- AbiConstructor
- InstantiateProps
- CodeSubmittableResult
- BlueprintSubmittableResult
- BlueprintPromise
- Step2FormData
- TxOptions
- TransactionsQueue
- Keyring
- DbQuery
- UseBalance
- CodeBundle
- ValidateFn
- MetadataState
- UseStepper
- UseToggle
- Party
- Restaurant
- BoardMember
- Id
- Label
- Priority
- Avatar
- PriorityValue
- AuthSetup
- IColumn
- Board
- ITask
- TaskComment
- NewTaskComment
- WithTheme
- UserDetail
- TasksByColumn
- NewTask
- ValueOf
- APIResponse
- Nullable
- Currency
- Route
- Author
- Post
- Category
- Watch
- ComputeCallback
Other Related APIs
- react#useState
- react#useCallback
- react#createContext
- react#useContext
- react-router#useParams
- react-router#useNavigate
- types#InstantiateData
- types#SubmittableExtrinsic
- types#OnInstantiateSuccess$Code
- types#OnInstantiateSuccess$Hash
- types#InstantiateState
- types#ContractPromise
- types#CodeSubmittableResult
- types#BlueprintSubmittableResult
- types#BlueprintPromise
- types#Step2FormData
- @polkadot/types/interfaces#ContractInstantiateResult
- @polkadot/util#BN_THOUSAND
types#InstantiateProps TypeScript Examples
The following examples show how to use
types#InstantiateProps.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InstantiateContext.tsx From contracts-ui with GNU General Public License v3.0 | 4 votes |
export function InstantiateContextProvider({
children,
}: React.PropsWithChildren<Partial<InstantiateProps>>) {
const navigate = useNavigate();
const dbState = useDatabase();
const apiState = useApi();
const NOOP = () => Promise.resolve();
const { codeHash: codeHashUrlParam } = useParams<{ codeHash: string }>();
const [currentStep, stepForward, stepBackward, setStep] = useStepper(initialState.currentStep);
const [data, setData] = useState<InstantiateData>(initialState.data);
const [[tx, onInstantiate], setTx] = useState<TxState>([null, NOOP, null]);
const [dryRunResult, setDryRunResult] = useState<ContractInstantiateResult>();
const onSuccess = useCallback(
(contract: ContractPromise, _?: BlueprintPromise | undefined) => {
navigate(`/contract/${contract.address}`);
dbState.refreshUserData();
},
[dbState, navigate]
);
const onFinalize = (formData: Partial<InstantiateData>) => {
const newData = { ...data, ...formData };
try {
const tx = createInstantiateTx(apiState.api, newData);
const onInstantiate = (codeHashUrlParam ? onInsantiateFromHash : onInstantiateFromCode)(
dbState,
newData,
onSuccess
);
setTx([tx, onInstantiate, null]);
setData(newData);
stepForward();
} catch (e) {
console.error(e);
setTx([null, NOOP, 'Error creating transaction']);
}
};
const onFormChange = useCallback(
async (formData: Step2FormData) => {
try {
const constructor = data.metadata?.findConstructor(formData.constructorIndex);
const inputData = constructor?.toU8a(
transformUserInput(apiState.api.registry, constructor.args, formData.argValues)
);
const params = {
origin: data.accountId,
gasLimit: formData.weight || maximumBlockWeight(apiState.api),
storageDepositLimit: formData.storageDepositLimit,
code: codeHashUrlParam
? { Existing: codeHashUrlParam }
: { Upload: data.metadata?.info.source.wasm },
data: inputData,
salt: formData.salt || undefined,
value: formData.value
? apiState.api.registry.createType('Balance', formData.value)
: null,
};
if (params.origin) {
const result = await apiState.api.rpc.contracts.instantiate(params);
setDryRunResult(result);
}
} catch (e) {
console.error(e);
}
},
[apiState.api, codeHashUrlParam, data.accountId, data.metadata]
);
function onUnFinalize() {
setTx([null, NOOP, null]);
setStep(2);
}
const value: InstantiateState = {
data,
setData,
currentStep,
dryRunResult,
setStep,
stepForward,
stepBackward,
onSuccess,
onUnFinalize,
onFinalize,
onFormChange,
tx,
onInstantiate,
onError: NOOP,
};
return <InstantiateContext.Provider value={value}>{children}</InstantiateContext.Provider>;
}