Create Contract
Create a smart contract on Arweave
The createContract
function creates a contract based on the input parameters. The contract can be created either on the mainnet
or on a testnet/ local network
for testing purposes.
Basic Syntax
The function is called as follows:
Input Parameters
The following params are available for this function and they must be passed in as an object:
wallet: ArWallet | string
(optional) : The wallet for deploying the contract with. The typeArWallet
basically checks for Arweave wallet of the typeJWKInterface
and typeString
expects the private key of the Ethereum wallet and if the wallet param is not passed, it falls back to check for a web-based wallet like Metamask or ArConnect. When falling back to a web wallet, an Ethereum Wallet (like Metamask) is triggered since contract functions use bundling by default, which supports EVM web wallets. If this attempt fails, the function will retry with an Arweave Web Wallet (like ArConnect or arweave.app). The wallet key file can be loaded as follows and passed to the wallet param:
Arweave JWK
or Ethereum Private key
is needed as a wallet parameter in the node environment. And, the wallet param needed not to be passed in the browser environment for use with Arconnect
or an Ethereum-based wallet (like Metamask)
.
In order to explicitly use an Arweave Web Wallet, use_wallet
must be passed into the wallet param, which also disables bundling in order to successfully process the function call.
For deploying a contract on mainnet
please ensure the wallet of choice has funds.
initialState: string
: The initial state of information for the contract at the time of deployment instring
format. TheinitState
file can be passed in directly as a string or read from a file as follows:
contractSource: string | Buffer
: The contract source parameter can either be the source code or a transaction ID to an existing source code. Contract data (logic) read from a file that must be encoded inutf-8
a format that returns astring
. The contract source file can be loaded or it can be a contract source transaction ID as follows:tags: array
(optional) : Tags can be added to any transaction for ease of indexing and querying. The syntax for adding tags is as follows:The
name
is the key for a givenvalue
that can be used for querying the transaction in the future. By default, the library adds the'ArweaveKit' : '1.5.1'
tag on the backend to help identify the library and version used to deploy the function.data: object
(optional): It acceptsContent-Type
of the data and thebody
of the data so the data can be accessed with the same deployed contract transaction ID making it an atomic asset.evaluationManifest : object
(optional): The evaluation manifest defines rules that must be used when evaluating the contract being deployed. This includes evaluation options as well as any plugins that the contract deployment may need. Read more about evaluation options and contract manifests to learn about the available configurations and their uses. Learn more about plugins here.environment: 'local' | 'testnet' | 'mainnet'
: The environment of choice to create the smart contract in. Thetestnet
is a pseudo-testing environment created on top of themainnet
with the help of custom tags.
An arlocal
instance must be running on the port 1984
for the function to work with the local environment. To create one, simply run npx arlocal
in the command line. Learn more about arlocal
here.
strategy : 'arweave' | 'ethereum' | 'both'
(optional) : The strategy specifies the wallet (Ethereum or Arweave) to be used for contract creation. While the wallet can be determined by the wallet param passed in, it can be beneficial to pass in when using the browser environment. However, by default, the strategy is set to'both'
and thus tries the function call with Ethereum first and fallback on an Arweave Wallet.
Returned Data
The function call returns the following data:
contract: ContractDeploy
: The contract object has relevant transaction IDs for future interactions. Read more about it here.contractTxId: string
: ThecontractTxId
is a unique identifier for further interactions with the contract like read and write operations. It is an instance of the contract source that is uploaded on the network.status: object
: Theresult
object returns easy to understand information showing the status of the contract deployment.code: 200
andmessage: 'SUCCESSFUL'
indicate that the contract has been successfully deployed to the network.
Last updated