Call a Contract
How to perform a contract call.
Call a contract
A contract call is the equivalent to launching a blockchain transaction. We've already covered that we can't execute a transaction without the user's approval. Therefore to be able to call a contract we will need to do two things i) define the contract call and ii) ask the user for his approval.
The object that can ask the user for his approval is called a Signer
, once we've created a Signer
object we can use the Signer
to perform the contract call.
To perform actions on a wallet , such as transactions or signatures, the wallet has to be linked to your application. The easiest way to link a wallet to your application in to use getAccount flow. The benefits of using the getAccount flow is that this flow bundles multiple actions into one call.
Function:
//Asking the signer to transfer a certain value to a certain destination.
venlyConnect.signer.executeContract({
secretType: '<BLOCKCHAIN>',
walletId: '<WALLET_ID>',
to: '<BLOCKCHAIN ADDRESS>',
value: 0,
functionName: '<CONTRACT_FUNCTION_NAME>',
inputs: [
{type: "address", value: "0x80cbb6c4342948e5be81987dce8251dbedd69138"},
{type: "uint256", value: "73680000"}
]
})
Example:
venlyConnect.signer.executeContract({
secretType: 'ETHEREUM',
walletId: '71dec640-4eb8-4321-adb8-b79461573fc4',
to: '0xf147cA0b981C0CD0955D1323DB9980F4B43e9FED',
value: 0,
functionName: 'transfer',
inputs: [
{type: "address", value: "0x80cbb6c4342948e5be81987dce8251dbedd69138"},
{type: "uint256", value: "73680000"}
]
})
Returns:
{
status: "SUCCESS",
result: {
id: "046b6c74-e681-4398-a932-546c8c25034d",
transactionHash: "0x7889109ae7a929a968f1d86a6efe396129d1f72a6df574a051516ef247e8a616"
}
}
JS Fiddle Example
The following is an example of a burn contract call to burn an NFT.
Function Reference
The function reference describes the different functions that are available in the Widget. For each function you can find the signature, it's parameters, and possible options documented.
Updated 27 days ago