Creating custom transactions
Throughout our service we’ve added multiple methods for you to manage assets for the Profiles you’ve created. However, as your game and asset contract complexity grows, a more interesting way of handling complicated transactions is by directly communicating with an asset contract.
You can simply do this by creating a transaction that interacts with one or more contracts in one go by padding an interactions
array. This would look something like the snippet below. Keep in mind that everything you see below is completely contextual based on the contracts you’re calling and the functions that are available on said contract.
const transaction = await beam.transactions.createTransaction("entity-id-of-user", {
interactions: [
{
contract: "0x9eeaecbe2884aa7e82f450e3fc174f30fc2a8de3", // 👈 the asset contract you're calling
functionName: "_mint", // 👈 functions are defined in the asset contract you're calling
functionArgs: ["0x000..", "arg-2", "arg-3", "arg-4"], // 👈 this completely depends on the function you're calling
},
],
});
// {
// "status": "success",
// "transactionHash": '0x71f3f259568e9875c41a4350a3912a3a7650d9321ccd1d57641241128b4e504f',
// "explorerUrl": "https://subnets.avax.network/beam/0x71f3f259568e9875c41a4350a3912a3a7650d9321ccd1d57641241128b4e504f"
// }
- NOTE: There’s a limit of 9 interactions per transaction to prevent potential security vulnerabilities. Making calls to external contracts within loops can risk Denial of Service (DoS) or transaction failures if they consume more gas than a block’s limit.
Passing structs as function arguments
If your smart contract function accepts a struct as an argument:
struct MyStruct {
uint256 intProp;
string stringProp;
bool boolProp;
}
function testNonPure(uint256 _arg1, MyStruct memory _arg2) public returns (string memory) {
...
}
You can pass it using an array like this:
const transaction = await beam.transactions.createTransaction("entity-id-of-user", {
interactions: [
{
contract: "0x89fFf7409b261d19edad2c0852Baa005a1330c4C",
functionName: "testNonPure",
functionArgs: [123, [1, [2,"somestring",true]] // 👈 pass each struct field as an array element, order and type matters!
},
],
});